如何使位图(在src中设置)压缩?

时间:2015-08-15 09:08:38

标签: java android eclipse android-studio bitmap

我写了一个通用的自定义ImageView,有部分代码:

public class AvatarImageView extends ImageView {
@Override
protected void onDraw(Canvas canvas) {

Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
 // I want to make this bitmap compress

}

然后我可以像这样使用这个自定义ImageView:

<CustomerView.AvatarImageView
                 android:layout_width="60dp"
                 android:layout_height="60dp"
                 android:src="@drawable/avatar"
                 />

当我在listview中设置2个以上的AvatarImageViews时,会导致oom错误。
  我看到很多开发人员都是这样做的:Google Training Loading Large Bitmaps Efficiently

BitmapFactory.decodeResource(res, resId, options);

需要提供resId。但我想重复使用这个自定义ImageView,因此我无法提供某个ID

有什么好的解决方案吗?任何帮助都会非常感谢。谢谢!

0 个答案:

没有答案