回收位图 [英] Recycling bitmaps

查看:175
本文介绍了回收位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作项目,包括位图的操作。因为我不希望有OutOfMemoryError而我试图回收未使用的每一个位图。可惜的是我已经回收了太多,已经尝试使用回收的位图的错误。

I am working on project which involves operations on bitmaps. Because I don't want to have OutofMemoryError I'm trying to recycle each of unused bitmap. Unfortunatelly I've recycled too much and have 'trying to use a recycled bitmap' error.

我使用的:

 Bitmap.createBitmap(bmp, x,y,w,h, matrix, false);
 Bitmap.createScaledBitmap(bmp, w, h,true);

我应该回收BMP这个方法之后,或者是由他们回收?这样的:

Should I recycle bmp after this methods or it is recycled by them? Like:

Bitmap newBitmap = Bitmap.createBitmap(bmp, x,y,w,h, matrix, false);
bmp.recycle();

我可以只后imageView.setImageBitmap()回收其中一个previously用在这里?例如。

Can I just after imageView.setImageBitmap() recycle one which previously was used here? E.g.

myImageView.setImageBitmap(myBitmap);
myImageView.setImageBitmap(newBitmap);
myBitmap.recycle();

感谢您的帮助。

推荐答案

您应该只回收一个位图时,你不需要它了。但是,您需要一个位图,当你想的显示的它。如果你不希望显示它,那么你可以回收的位图。

You should only recycle a bitmap when you do not need it anymore. However, you do need a bitmap when you want to display it. If you don't want to display it, then you can recycle a bitmap.

这篇关于回收位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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