Can the code below cause OutOfMemory ? I think it allows to exceed the application memory limit.
Matrix matrix = new Matrix();
matrix.postRotate(orientation);
image = Bitmap.createBitmap(image, 0, 0, image.getWidth(), image.getHeight(), matrix, true);
What is the best way to rotate an image in Android ?
Allocate it in a service in a new process to get more heap?
@CommonsWare said in this link [1] that many developers think that more heap is a solution for inefficient coding.
This question indicates large heap too [2].
Is there a simpler solution ?
[1] Can you start an IntentService on a separate process?
[2] How to avoid OutOfMemory ex while rotating the image?
The short answer is, Yes, this code may cause OutOfMemory. I don't think that there is a simpler solution than increasing app heap size. I believe that @CommonsWare is right, and often OutOfMemory is an indication of wrong programming. But there are some situations when you need, ehm, huge memory. Rotation of a huge image is definitely one of such situations.
You can use native code (NDK) instead of asking for increased heap size, but this is definitely not easier. And it will still needs lots of memory, so there is no advantage in going for C++ (except that it works on 2.3).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With