Bitmap size difference for devices with same density, inches and resolution

青春壹個敷衍的年華 提交于 2019-12-11 11:29:17

问题


I have two tablet devices:

1) Asus Memo Pad 172V tablet

Specs given online as: 600 * 1024 pixels, 7.0 inches (~170 ppi pixel density) LINK

Specs through code: 1024 * 552 pixels, 7.0 inches (160 ppi pixel density)

2) MID 7510 tablet

Specs given online as: 800 * 480 pixels, 7.0 inches (no density mentioned anywhere) LINK

Specs through code: 1024 * 552 pixels, 7.0 inches (160 ppi pixel density)

My problem is:

- Both the tablets have the same density and resolutions (by code), so how can I distinguish between them in order to set the bitmap height (width is coming correct for both) as in case of MID7510, the bitmap height is extended slight down.

- Is there any other factors that are responsible for causing different bitmap sizes for both
tablets ?

- Why are specs coming different by code and are given different online ?

Code to get density and resolution:

 DisplayMetrics dm = new DisplayMetrics();
 getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);                       

    int screenWidth = dm.widthPixels;
    int screenHeight = dm.heightPixels;                     

    // Display device dpi (density) value in pixels
    int screenDPIy = (int)dm.ydpi;

回答1:


I'll try to answer to each question but I'll start by the more important one:

- Why are specs coming different by code and are given different online?

Because you find online what material is used for the device, its usually the correct values. You find by code specifications that are set up by the constructor when they are building their android version for their devices. Meaning : it can be false! especially for devices from unknown constructor or Chinese low cost such as 'weisung'.

Given that, answers for the other questions:

- Is there any other factors that are responsible for causing different bitmap sizes for both tablets?

I dont think so, they have got different screen size and density but system think they are the same... it explain the difference on the final bitmap size.

- How can I distinguish between them?

Definitively not from the screen specifications. If you really need to manage 'weisung' devices you can always check for manufacturer in the device configuration by code. (Assuming they have correctly set up their identification in the manufacturer field XD)

Check the constant value : android.os.Build.MANUFACTURER

I'm really interested to know more in this topic too so any more information is welcome.




回答2:


The chart was on drawable-hdpi folder.

I was doing simply this:

img.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));

The height was not proper in MID 7510 doing so.

Setting height like this worked for both the tablets:

static int imgHeight = 0;

Drawable d = (BitmapDrawable) getResources().getDrawable(R.drawable.chart);

imgHeight = d.getIntrinsicHeight(); 

final ImageView img = new ImageView(getActivity());

img.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, (int) (imgHeight * 1.5)));

This is because 1 hdpi= 1.5 mdpi. So total height should be 1.5 times of image height.



来源:https://stackoverflow.com/questions/18531532/bitmap-size-difference-for-devices-with-same-density-inches-and-resolution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!