开发者

android how to load/save original size Bitmap with no OutOfMemory

I read many discussions about the inSampleSize OutOfMemory dilemma.

Cannot get a good solution so i ask a question about it.

Im currently loading a bitmap with inSampleSize=4.

That will give me a Bitmap with the size 648x388.

Original On disk size is 2592x1592.

Im writing text on 648x388 bitmap and saving it back to disk.

Im writing on the 648x388 because the 2592x1592 give me OutOfMemory .

The way it works is that there can be 1-10 648x388 Bitmaps to be saved in a while loop.

I want to change this loop to save 1-10 2592x1592 Bitmaps.

How can i securely load the 2592x1592?

I don care about the resolution going down 60% or more.

As long as the Bitmap has the same size 2592x1592.

Is there a way to maybe keep the size but make Bitmap thinner,

removing color without making quality bad.

My first thought was going something like this to get the biggest bitmap i could get: I have not tested this but get a feeling it's a bad way

boolean work = true;
int insample = 2;
BitmapFactory.Options options = new BitmapFactory.Options();
while(work){
    try{
    options.inSampleSize = insample;
        bitmap = BitmapFactory.decodeFile(filePath,options);
 开发者_StackOverflow社区       work = false;
    }catch(Exception e){
        insample++;
    }
}

any help would be grate.


Image processing requires a lot of memory. you cant use the whole bitmap and just modify it on your phone. use a web service for that. upload, process, download. sorry there is no other way a decoded bitmap just takes a lot of memory.

And by the way you cant catch an outOFMemory Exception. the app just crashes.


There's a hard limit on process size in Android and a 4 mega-pixel image at four bytes a pixel will hit it all by itself (on many devices), without any room for your program.

I think you are going to need to do one of two things: Create a web service to do the image processing on a server/in the cloud; or learn to do your image processing "on-the-fly" by manipulating the data directly instead of using a bitmap.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜