Recycle ImageView's Bitmap

后端 未结 4 763
谎友^
谎友^ 2020-11-27 14:06

I have something like this:

Bitmap.Config conf = Bitmap.Config.ARGB_8888;
WeakReference bm = new WeakReference(Bitmap.createBitma         


        
4条回答
  •  孤街浪徒
    2020-11-27 14:42

    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();
    }
    

    The cast should work since setImageBitmap is implemented as

    public void setImageBitmap(Bitmap bm) {
        setImageDrawable(new BitmapDrawable(mContext.getResources(), bm));
    }
    

提交回复
热议问题