java如何使位图(在src中设置)压缩?
我编写了一个通用自定义ImageView,其中有部分代码:
public class AvatarImageView extends ImageView {
@Override
protected void onDraw(Canvas canvas) {
Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
// I want to make this bitmap compress
}
然后我可以像这样使用这个自定义图像视图:
<CustomerView.AvatarImageView
安卓:layout_width="60dp"
安卓:layout_height="60dp"
安卓:src="@drawable/avatar"
/>
当我在listview中设置超过2个AvataRimageView时,它将导致oom错误
我看到很多开发人员都是这样做的:Google Training Loading Large Bitmaps Efficiently
BitmapFactory.decodeResource(res, resId, options);
它需要提供一个resId。但是我想重用这个定制的ImageView,所以我不能提供特定的id
有什么好的解决办法吗
如有任何帮助,将不胜感激。谢谢大家!
共 (0) 个答案