Yes, the images from the camera are 2048px by 1536px. If you convert
to a bitmap, thats 2048 x 1536 x 2 = 6291456, or 6MB. This is right
at the allotted space an Activity gets. If you can live with smaller
images, I would suggest using a sampleSize of > 1 when decoding the
image. This will result in a smaller image size, thus less memory
used. I have used the following code in the past to keep my images
under a set byte count. Alternatively, you could forget about
calculating the sample size and just set it to 2. This would use
1.5MB instead of 6MB on a standard image.
//Get dimensions of image first (takes very little time)
BitmapFactory.Options bfo = new BitmapFactory.Options();
bfo.inJustDecodeBounds = true;
bfo.inDither = false;
bfo.inPreferredConfig = Bitmap.Config.RGB_565;
BitmapFactory.decodeStream(cr.openInputStream(uriAvator),null, bfo);
//Calculate sample size to keep image under maxFileSize
int maxFileSize = 1572864; //in bytes
int sampleSize = 1;
long fileSize = 2 * (bfo.outWidth/sampleSize) * (bfo.outHeight/
sampleSize);
while(fileSize > maxFileSize)
{
sampleSize++;
fileSize = 2 * (bfo.outWidth/sampleSize) * (bfo.outHeight/
sampleSize);
}
//Decode image using calculated sample size
bfo.inSampleSize = sampleSize;
bfo.inJustDecodeBounds = false;
bmpAvator = BitmapFactory.decodeStream(cr.openInputStream
(uriAvator),null, bfo);
-Mike-