我有问题的内存不足我的位图。这是code:
I have problem with out of memory with my bitmap. This is code:
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());
一切正常,但是当我改变方向,我得到内存溢出。我怎样才能解决我的问题?我想softreference,但我不知道我怎么可以用它来位图。你知道吗?
everything is ok but when I change orientation I get outOfMemory. How can I solve my problem? I am thinking about softreference but I don't know how can I use it to bitmap. Any idea?
回收您的位图,当你开始的活动
Recycle your bitmap when you start activity
if(bitmap!=null){
bitmap.recycle();
bitmap=null;
}
See这也