stoefln
stoefln

Reputation: 14556

android: How to improve memory management for image processing

I'm trying to rotate a camera image. The code looks like that:

Bitmap result = Bitmap.createBitmap(bitmap.getHeight(), bitmap.getWidth(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(result);
canvas.save();
canvas.rotate(90);
canvas.translate(0, -1*bitmap.getHeight());
canvas.drawBitmap(bitmap, new Matrix(), null);
canvas.restore();
String path = String.format(dir+"pic_%d.jpg", System.currentTimeMillis());
stream = new FileOutputStream(path);
bitmap.compress(CompressFormat.JPEG, this.imageQuality, stream);
stream.flush();
stream.close();

Problem is: I'm getting an OutOfMemoryException (first line). Is there some way to get this done by an extra thread or some other solution? Downscaling the image is currently not an option.

Upvotes: 1

Views: 351

Answers (1)

jbowes
jbowes

Reputation: 4150

If you don't need an alpha channel in your image, you can use RGB_565 instead of ARGB_8888. That will save you 2 bytes per pixel.

Upvotes: 2

Related Questions