Bitmap.Config conf = Bitmap.Config.ARGB_8888;
WeakReference<Bitmap> bm = new WeakReference<Bitmap>(Bitmap.createBitmap(3000 + 3000, 2000, conf));
Canvas canvas = new Canvas(bm.get());
canvas.drawBitmap(firstBitmap, 0, 0, null);
canvas.drawBitmap(bm, firstBitmap.getWidth(), 0, null);
imageView.setImageBitmap(bm);
---------------orintation memory leak
private ImageView miniPicture;
private String imagePath;
private WeakReference<Bitmap> imageBitmap;
....
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 8;
imageBitmap = new WeakReference<Bitmap>(BitmapFactory.decodeFile(imagePath, options));
miniPicture.setImageBitmap(imageBitmap.get());--------------
In your onDestroy method you could try something like this:
ImageView imageView = (ImageView)findViewById(R.id.my_image);
Drawable drawable = imageView.getDrawable();
if (drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
Bitmap bitmap = bitmapDrawable.getBitmap();
bitmap.recycle();
}
public void setImageBitmap(Bitmap bm) {
setImageDrawable(new BitmapDrawable(mContext.getResources(), bm));
}
本文介绍了一种使用WeakReference和Bitmap来减少Android应用内存占用的方法,包括如何创建和回收位图资源,以及在Activity销毁时释放资源的具体实现。
355

被折叠的 条评论
为什么被折叠?



