BitmapDrawable: prevent garbage collection while in use

This commit is contained in:
Julian Winkler
2024-08-05 22:57:28 +02:00
parent 5a73787a3d
commit 9fda1b36e6
2 changed files with 4 additions and 6 deletions

View File

@@ -36,7 +36,8 @@ public class BitmapDrawable extends Drawable {
throws XmlPullParserException, IOException {
final TypedArray a = r.obtainAttributes(attrs, R.styleable.BitmapDrawable);
if (a.hasValue(R.styleable.BitmapDrawable_src)) {
paintable = a.getDrawable(R.styleable.BitmapDrawable_src).paintable;
bitmap = ((BitmapDrawable)a.getDrawable(R.styleable.BitmapDrawable_src)).bitmap;
paintable = bitmap.getTexture();
}
a.recycle();
}

View File

@@ -7,7 +7,6 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.PorterDuff;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
@@ -61,12 +60,10 @@ public class ImageView extends View {
public void setImageDrawable(Drawable drawable) {
this.drawable = drawable;
if (drawable instanceof BitmapDrawable) {
setImageBitmap(((BitmapDrawable) drawable).getBitmap());
} else if (drawable != null && drawable.paintable != 0) {
if (drawable != null) {
drawable.setCallback(this);
native_setDrawable(widget, drawable.paintable);
}
native_setDrawable(widget, drawable != null ? drawable.paintable : 0);
}
public void setImageMatrix(Matrix matrix) {}