Android的PNG图像大内存图像、内存、Android、PNG

2023-09-06 00:05:18 作者:安于现状 丶

我在android的,有一个imageflipper的应用程序。问题是,经过约8个图像加载到内存中,我得到一个内存不足的错误。

I have an application in android that has an imageflipper. Problem is, after about 8 images loaded to memory, I get an out of memory error.

嗯,我试着做动态的图像加载,因此,如果用户翻转2图像,我会加载未来2至存储和删除2首当其冲。那种它的工作原理,但它是丑陋的,我有麻烦,当用户翻转图像回(imageflipper.show previous()),我真的不能转移所有图像,并把新的图像开始。

Well, I tried to do dynamic image loading, so that if the user flips 2 images, I'll load next 2 to memory and delete 2 first ones. It kind of works, but it is ugly and I have trouble when user flips images back(imageflipper.showprevious()), I can't really shift all images and place new images to the beginning.

我的问题是: 有没有更好的办法做这样的东西?调整图像大小并没有真正的帮助。

My question is: Is there a better way to do this kind of stuff? Resizing images didn't really help.

推荐答案

使用的 BitmapFactory.Options

BitmapFactory.Options opts = new BitmapFactory.Options();
opt.inSampleSize = 2;
//this will decrease bitmap size,
// but also affect quality of the image, 
//so just play with this value to spot the good one;
Bitmap b = BitmapFactory.decodeFile(fileName, opts);