【发布时间】:2013-07-19 11:19:15
【问题描述】:
我的位图内存不足。这是代码:
Uri bitmapPictureUri = intent.getParcelableExtra(TaskActivity.PHOTO);
Bitmap bitmap = null;
try {
bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), bitmapPictureUri);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int nh = (int) (bitmap.getHeight() * (512.0 / bitmap.getWidth()));
bitmapPicture = Bitmap.createScaledBitmap(bitmap, 512, nh, true);
picture.setImageBitmap(bitmapPicture);
fileName.setText(tNameText+"_"+getCurrentTime());
一切都很好,但是当我改变方向时,我会失去记忆。我该如何解决我的问题?我正在考虑软引用,但我不知道如何将它用于位图。有什么想法吗?
【问题讨论】:
-
您需要先阅读此开发指南部分:developer.android.com/training/displaying-bitmaps/index.html。不要使用
SoftReferences,因为 GC 对它们非常有攻击性,而且它们的收集速度比你想象的要快。而不是使用LRUCahce。