Changing ImageView content causes OutOfMemoryError

后端 未结 5 490
渐次进展
渐次进展 2021-02-04 02:14

I have a very simple application with one ImageView and a Button. The first Drawable resource loaded by my ImageView is specified with the \"android:src\" tag i

5条回答
  •  难免孤独
    2021-02-04 03:03

    The problem has now been solved. rather than only one line:

    ((BitmapDrawable)imageView.getDrawable()).getBitmap().recycle(); 
    

    add this code before updating ImageView content:

    Drawable toRecycle= gallerypic.getDrawable();
    if (toRecycle != null) {
        ((BitmapDrawable)gallerypic.getDrawable()).getBitmap().recycle();
    }
    gallerypic.setImageURI(selectedimage);
    

提交回复
热议问题