对于相同的密度,英寸和分辨率的设备位图大小差异 [英] Bitmap size difference for devices with same density, inches and resolution
问题描述
我有两个平板设备:
1)华硕便笺172V平板电脑
600 * 1024像素,7.0英寸(170〜PPI像素密度)链接:在线给出的规格
通过code规格:1024 * 552像素,7.0英寸(160 ppi的像素密度)
2) MID平板电脑7510
鉴于网上的规格:800×480像素,7.0英寸(没有提及任何地方密度)的链接
通过code规格:1024 * 552像素,7.0英寸(160 ppi的像素密度)
我的问题是:
- 无论是平板电脑具有相同的密度和决议(由code),所以我怎么能才能设置位图高度区分它们(宽度来都正确)在 MID7510
的情况下,位图高度扩展轻微下降。
- 是否有负责造成不同的位图尺寸为结果的其他因素
片?
- 为什么规格过来了code不同,给予不同的在线
code得到的密度和精度:
DisplayMetrics DM =新DisplayMetrics();
。getActivity()getWindowManager()getDefaultDisplay()getMetrics(DM)。; INT屏幕宽度= dm.widthPixels;
INT screenHeight = dm.heightPixels; 以像素为单位//显示装置DPI(密度)值
INT screenDPIy =(INT)dm.ydpi;
该图是在绘制,华电国际
文件夹中。
我是做简单:
img.setLayoutParams(新LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT));
的高度是不正确的 MID 7510 这样做。
设置这样的高度工作既片:
静态INT imgHeight = 0;可绘制D =(BitmapDrawable)getResources()getDrawable(R.drawable.chart)。imgHeight = d.getIntrinsicHeight();最后ImageView的IMG =新ImageView的(getActivity());img.setLayoutParams(新LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,(int)的(imgHeight * 1.5)));
这是因为 1华电国际= 1.5 MDPI 。所以总高度应该是图像高度的1.5倍。
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;
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.
这篇关于对于相同的密度,英寸和分辨率的设备位图大小差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!