0

我正在将 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,我得到了相同的结果。

4

1 回答 1

2

你的代码应该像这里提到的那样工作,但不明白为什么它不工作..

添加这些行

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

1 将按此处所写的方式工作

"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."
于 2013-12-19T09:22:48.680 回答