怎样的android加载/保存原始大小的位图,没有内存不足 [英] android how to load/save original size Bitmap with no OutOfMemory

查看:188
本文介绍了怎样的android加载/保存原始大小的位图,没有内存不足的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看了一下inSampleSize内存不足的困境多次讨论。结果
所以我想问一个关于它的问题不能得到很好的解决。结果
即时通讯目前与加载= inSampleSize 4位图。结果
这将使我的大小648x388的位图。结果
原来在磁盘上的大小是2592x1592。

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.

这是648x388的位图,并将其保存到磁盘我写的文字。结果
我写的648x388,因为2592x1592给我的内存不足。

Im writing text on 648x388 bitmap and saving it back to disk.
Im writing on the 648x388 because the 2592x1592 give me OutOfMemory .

它的工作方式是可以有1-10 648x388位图保存在,而循环。结果
我想改变这种循环,以节省1-10 2592x1592位图。

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.

如何才能安全地装载2592x1592?结果
我不关心的分辨率会下降60%以上。结果
只要位图具有相同的尺寸2592x1592。结果
有没有一种办法,也许保持一定的尺寸,但要位图更薄,结果
未做质量不好的去掉颜色。

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);
        work = false;
    }catch(Exception e){
        insample++;
    }
}

任何帮助将是篦。

any help would be grate.

推荐答案

图像处理需要大量的内存。你不能使用整个位图,只是修改您的手机上。用于该web服务。上传,处理,下载。抱歉,有一个去codeD位只是需要大量的内存没有其他办法。

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.

顺便说一句,你不能赶上一个OutOfMemory例外。该应用程序崩溃只是

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

这篇关于怎样的android加载/保存原始大小的位图,没有内存不足的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆