2

My code:

BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inJustDecodeBounds = true;
Bitmap rotateBmp = BitmapFactory.decodeFile("/storage/sdcard0/FastBurstCamera/2014-09-15 05-24-07-461.jpg", opt);

The file /storage/sdcard0/FastBurstCamera/2014-09-15 05-24-07-461.jpg exists, but the rotateBmp is null, why?

Victor S
  • 4,021
  • 15
  • 43
  • 54

2 Answers2

3

The file /storage/sdcard0/FastBurstCamera/2014-09-15 05-24-07-461.jpg exists, but the rotateBmp is null, why?

Because that's what you asked for.

Quoting the documentation for decodeFile() (emphasis added):

The decoded bitmap, or null if the image data could not be decoded, or, if opts is non-null, if opts requested only the size be returned (in opts.outWidth and opts.outHeight)

Quoting the documentation for inJustDecodeBounds:

If set to true, the decoder will return null (no bitmap), but the out... fields will still be set, allowing the caller to query the bitmap without having to allocate the memory for its pixels.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanks for your kindly answer, according to your suggestion, I removed the "opt.inJustDecodeBounds = true;", then it works. Thank you again! – Victor S Sep 23 '14 at 11:57
2
  • The reason may be the image size is big. Check this question.
  • Another reason may be not adding READ_EXTERNAL_STORAGE and/or WRITE_EXTERNAL_STORAGE permissions to your manifest file. Did you add?
Community
  • 1
  • 1
Batuhan Coşkun
  • 2,961
  • 2
  • 31
  • 48