ImageView中可绘制的尺寸不同的位图尺寸,它是否已缩放?

时间:2016-08-11 04:57:30

标签: android bitmap

我的图像是从文件URI的输入流解码的结果。提取代码如下:

BitmapFactory.Options options = new BitmapFactory.Options();
options.inScaled = true;
options.inSampleSize = bitmapSampleSize;

float scaleW = targetWidth/(sourceDims.x/bitmapSampleSize);
float scaleH = targetHeight/(sourceDims.y/bitmapSampleSize);

int initialDensity, targetDensity;
if(scaleW > scaleH)
{
    initialDensity = sourceDims.x;
    targetDensity = targetWidth*bitmapSampleSize;
}
else
{
    initialDensity = sourceDims.y;
    targetDensity = targetHeight * bitmapSampleSize;
}
options.inDensity = initialDensity;
options.inTargetDensity = targetDensity;
is = context.getContentResolver().openInputStream(pictUri);
bitmap = BitmapFactory.decodeStream(is, null, options);

当我尝试从资源中解码64x64图像使其成为400x400时,出于某种原因,当我在ImageView中设置它时,我得到的drawable返回640x640。

当我尝试从文件中解码5312x2988照片以使其成为1820x1024时,我从ImageView获取的可绘制内容仅为786.8x442.5。

这是为什么?是否与inScaled有关? inScaled屏幕密度是否依赖?

编辑:我不使用decodeResource(),资源中的URI如下:

final Uri imageUri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + getResources().getResourcePackageName(R.drawable.filter_aomi) + '/' +
            getResources().getResourceTypeName(R.drawable.filter_aomi) + '/' + getResources().getResourceEntryName(R.drawable.filter_aomi));

0 个答案:

没有答案