1

This is my code to load Bitmap into ImageView from filepath retrieved from another activity.
I can get file, but Bitmap is always null.

I have tried with 250kb image code works fine but it does not work with 1.5MB images.How to resolve this issue?

Logcat message:

skia:           --- SkImageDecoder::Factory returned null
Choreographer:  Skipped 855 frames! `The application may be doing too much work on its main thread`.

code

Bundle extras = getIntent().getExtras();
if (extras != null) {
    String imagepath = extras.getString("FILEPATH1");
    File imgFile = new  File(imagepath);
        if(imgFile.exists()){                   
            Bitmap bitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());                    
            imgCaptured.setImageBitmap(bitmap);                         
        }           
    }
}
Kevan
  • 67
  • 1
  • 8

1 Answers1

2

As Javadocs say:

Returns: the resulting decoded bitmap, or null if it could not be decoded.

So, if you successfully can load a small bitmap from the same file but larger file fails, it is a strong indicator to the size being a problem. Most likely decoding the 1.5M JPEG file would result in a bitmap that is over 10M in size. Your phone can not load an image that big.

BTW, you can estimate the uncompressed size of the image by multiplying the width and height and multiplying that by 4 (one byte per channel: red, green, blue, alpha).

For example, a 2.6M JPEG that has 4128x2322 pixels takes about 38340000bytes (38M) when uncompressed.

This may help: Handling large Bitmaps

Community
  • 1
  • 1
Torben
  • 3,805
  • 26
  • 31
  • 1
    On Android Developers website is nice article about loading large images efficiently http://developer.android.com/training/displaying-bitmaps/load-bitmap.html – Damian Petla Aug 13 '14 at 12:50