Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load large images into Bitmap?

I'm trying to make a basic application that displays an image from the camera, but I when I try to load the .jpg in from the sdcard with BitmapFactory.decodeFile, it returns null.

It doesn't give an out of memory error which I find strange, but the exact same code works fine on smaller images.

How does the generic gallery display huge pictures from the camera with so little memory?

like image 646
Kleptine Avatar asked May 09 '10 18:05

Kleptine


People also ask

How do you handle a large bitmap?

Choose the most appropriate decode method based on your image data source. These methods attempt to allocate memory for the constructed bitmap and therefore can easily result in an OutOfMemory exception. Each type of decode method has additional signatures that let you specify decoding options via the BitmapFactory.

What is inSampleSize in Android?

inSampleSize. Added in API level 1. public int inSampleSize. If set to a value > 1, requests the decoder to subsample the original image, returning a smaller image to save memory. The sample size is the number of pixels in either dimension that correspond to a single pixel in the decoded bitmap.


1 Answers

Try to set the inSampleSize as shown in this example.

like image 132
Maurits Rijk Avatar answered Sep 30 '22 19:09

Maurits Rijk