0

I'm reading a jpg file into bitmap. The file I'm reading has dimensions 1600x1600 but the bitmap has dimensions 600x600. Why is it being scaled down? Here is my code:

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());

I get the following log:

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

As you can see I have the inScaled flag set to false. Why is it being scaled down?

EDIT: I even tried with inJustDecodeBounds and I got the same result.

nikmin
  • 1,803
  • 3
  • 28
  • 46

1 Answers1

2

Your code sholud work as mentioned here but not getting why it's not working..

Add these lines

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

1 will works as written 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."
Community
  • 1
  • 1
SweetWisher ツ
  • 7,296
  • 2
  • 30
  • 74
  • This way I got 300x300. That's even smaller :) – nikmin Dec 19 '13 at 09:24
  • it has to be int value – nikmin Dec 19 '13 at 09:27
  • and just to mention... images can have different sizes. – nikmin Dec 19 '13 at 09:27
  • I guess 1 will work.. 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. – SweetWisher ツ Dec 19 '13 at 09:28
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/43490/discussion-between-tamanna-and-nikmin) – SweetWisher ツ Dec 19 '13 at 09:29