简体   繁体   中英

Saving large image to PNG

I've just encontered a tough problem...

Here's my story:

My device is Samsung Galaxy Note, normally, it takes pictures at a resolution of 3264 * 2448 pixels. I love fine pictures when am tring to find detailed information, but here I hate it because it's huge to handle in Android. I can read and display an image of this big resolution, I need to draw lines on top of it, then I need to save both picture and lines to a png. My headache is that my Android always gives me Out of memery exception , when am trying to create a mutable bitmap like this:

    Bitmap bmp = Bitmap.createBitmap(3264, 2448, Config.RGB_565);
    Canvas cv = new Canvas(bmp);
    //draw a line and save and restore canvas
    // I found an alternative solution yet proven to be uncorrect:
    myImageView.setDrawingCacheEnabled(true);
    myImageView.buildDrawingCache(true);
    Bitmap bmp = myImageView.getDrawingCache();
    //save bmp to png

When the

bmp.width * bmp.height * 4 > getScaledMaximumDrawingCacheSize()

exception jumps out. I've tested myImageView.measure(...) and myImageView.layout(...) , didn't work for me. (Things are fine, when I test the same code using smaller images)

Any experts know how to kill this problem or throw a solution to me? Thanks!

Maybe not the definitve solution, but did you try to increase heap size?

For Android 2.2 or lower versions:

dalvik.system.VMRuntime.getRuntime().setMinimumHeapSize(sizeInBytes);

For Android 2.3 or or higher versions :

android:largeHeap="true"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM