我希望在(缩放,滤色,...)之后在屏幕上显示exacly位图,并使用其像素,例如为了删除透明像素:
for (int y = 0; y < sourceBitmap1.getHeight(); y++)
for (int x = 0; x < sourceBitmap1.getWidth(); x++)
if (sourceBitmap1.getPixel(x, y) == Color.TRANSPARENT) {
//todo do something
}
但是获取与目标Imageview相关的位图非常重要。正如我所看到的其他帖子可以用这种方法做到这一点:
public static Bitmap loadBitmapFromView(ImageView i) {
i.setDrawingCacheEnabled(true);
i.measure(FrameLayout.MeasureSpec.makeMeasureSpec(0, FrameLayout.MeasureSpec.UNSPECIFIED),
FrameLayout.MeasureSpec.makeMeasureSpec(0, FrameLayout.MeasureSpec.UNSPECIFIED));
i.layout(0, 0, i.getMeasuredWidth(), i.getMeasuredHeight());
i.buildDrawingCache(true);
Bitmap b = Bitmap.createBitmap(i.getDrawingCache(true));
i.setDrawingCacheEnabled(false);
return b;
}
但是方法返回null,任何想法? 谢谢先进
答案 0 :(得分:0)
尝试从imageview获取位图
Bitmap bitmap = ((BitmapDrawable) imgview.getDrawable()).getBitmap();