Android handling out of memory exception on image processing

允我心安 提交于 2019-12-28 07:03:08

问题


This is the sequence part of this question: Combining 2 Images overlayed

so the problem is: if the image size is too big - it'll got an exception (out of memory exception) what i want is, to handle even if the handset got the lower spec hardware, it doesn't go to that exception (but it'll take a longer time to process the image)

is it possible to do that?

the code snippet is like this:

public static Bitmap overlay(Bitmap bmp1, Bitmap bmp2) {
    Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
    Canvas canvas = new Canvas(bmOverlay);
    canvas.drawBitmap(bmp1, new Matrix(), null);
    canvas.drawBitmap(bmp2, 0, 0, null);
    return bmOverlay;
}

and that block of code is inside the async task.

I really appreciate if someone can help me on this matter.

Thank you and Regards, AnD


回答1:


I think you have no choice, but to rescale the bitmaps in a lower size...




回答2:


The only way I can think of to handle this would be to divide the images up into pieces so you don't have to keep everything in memory at once. If you don't want to keep bmp1 you can draw bmp2 directly on top of it rather then creating a new bitmap as well, though I'm not sure if this is what you're after.



来源:https://stackoverflow.com/questions/3724082/android-handling-out-of-memory-exception-on-image-processing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!