# getintrinsicwidth()/getIntrinsicHeight()大于或者小于图片实际像素大小

android:src="@drawable/aaa"

int intrinsicWidth = mImageView.getDrawable().getIntrinsicWidth();
int intrinsicHeight = mImageView.getDrawable().getIntrinsicHeight();
打印出来的结果发现大于图片的实际宽高；
度娘搜索无果，google一下，在stackoverflow【点我跳转】上找到了答案:原来我的测试设备是1080p，对应的图片资源文件应该是drawable-xxhdpi，但是这张图片位于drawable-xhdpi 目录下：
You said the drawable is from your /res folder. Which folder is it in?

/res/drawable
/res/drawable-mdpi
/res/drawable-hdpi

etc..

And what is the density of the device you are testing on? Is it a Nexus S with general density of 240dpi? Because if your source drawable is located in the drawable-mdpi folder and you are testing on a 240dpi device, then the Android system will automatically scale the drawable up by a factor of 1.5 so that the physical size will be consistent with the baseline device density at 160dpi.

When you call getIntrinsicWidth() what is returned is the size the drawable wants to be after Android scales the drawable. You'll notice that 2880 = 1920 * 1.5

If you placed the drawable in /res/drawable the Android system treats those drawables as meant for mdpi devices, thus the upscaling in your Nexus S. If this was meant for hdpi screens and you do not want this to upscale then try placing it in drawable-hdpi

就不翻译了，很老的常识问题，很简单，记录一下，免得忘记~





• 本文已收录于以下专栏：

## Android getIntrinsicWidth()获取到的值在不同的项目不同

private ImageView crossImageView; int crossWidth = crossImageView.getDrawable().getIntrinsicWidth();...

## 解决Android Bitmap内存溢出问题

android系统的手机在系统底层指定了堆内存的上限值，大部分手机的缺省值是16MB，不过也有些高配置的机型是24MB的，所以我们的程序在申请内存空间时，为了确保能够成功申请到内存空间，应该保证当前已...

## VC资源编辑器里对话框的大小和实际的像素尺寸显示问题

举报原因： 您举报文章：getintrinsicwidth()/getIntrinsicHeight()大于或者小于图片实际像素大小 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)