Android会在读取文件时阻止缩小位图

时间:2013-12-19 09:13:19

标签: android bitmap android-bitmap

我正在将jpg文件读入位图。我正在阅读的文件尺寸为1600x1600,但位图的尺寸为600x600。为什么要缩小规模?这是我的代码:

BitmapFactory.Options options = new BitmapFactory.Options();
options.inScaled = false;
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
options.inMutable = true;

b = BitmapFactory.decodeFile(imageFile, options);

Log.d("###", "bitmapWidth: " + b.getWidth());
Log.d("###", "bitmapHeight: " + b.getHeight());

我得到以下日志:

12-19 10:03:10.551: D/###(4125): bitmapWidth: 600
12-19 10:03:10.551: D/###(4125): bitmapHeight: 600

如您所见,我将inScaled标志设置为false。为什么要缩小规模?

修改 我甚至试过了inJustDecodeBounds,我得到了相同的结果。

1 个答案:

答案 0 :(得分:2)

您的代码应该按照提到的here工作,但不能解释为什么它不起作用..

添加这些行

  options.inDensity = 0;
  options.inTargetDensity = 0;
  options.inSampleSize = 1;

1将按书面here

的方式工作
"The sample size is the number of pixels in either dimension that correspond to a single pixel in the decoded bitmap. For example, inSampleSize == 4 returns an image that is 1/4 the width/height of the original, and 1/16 the number of pixels. Any value <= 1 is treated the same as 1. Note: the decoder uses a final value based on powers of 2, any other value will be rounded down to the nearest power of 2."
相关问题