任何人都可以告诉我删除图像上的油漆,在我的应用程序中,我准备了手指在图像上绘画,如果我想擦掉油漆,它会在图像上变成黑色而不是删除图像。我的代码是
public class MyView extends View {
int bh = originalBitmap.getHeight();
int bw = originalBitmap.getWidth();
public MyView(Context c) {
super(c);
//mBitmap = Bitmap.createScaledBitmap(originalBitmap,bw,bh,true);
mBitmap = Bitmap.createBitmap(bw,bh,Bitmap.Config.ARGB_8888);
mCanvas = new Canvas(mBitmap);
mPath = new Path();
mBitmapPaint = new Paint(Paint.DITHER_FLAG);
mBitmapPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
}
public MyView (Context c, int color) {
super(c);
mBitmap = Bitmap.createScaledBitmap(originalBitmap,bw,bh,true);
mCanvas = new Canvas(mBitmap);
mPath = new Path();
mBitmapPaint = new Paint(Paint.DITHER_FLAG);
mBitmapPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC)) ;
mCanvas.drawColor(color);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
/*mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
mCanvas = new Canvas(mBitmap);*/
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawColor(Color.TRANSPARENT);
canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
canvas.drawPath(mPath, mPaint);
}
用于油漆删除
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
最佳答案
您应该在放置在原始位图上的透明自定义 View 上绘制,而不是修改原始位图。这将使它保持简单。 为此你可以做
<RelativeLayout ....>
<ImageView ......set original bitmap to this/>
<CustomView ...... draw on this, you can erase too./>
</RelativeLayout>
要获取修改后的位图,请调用 RelativeLayout
上的 getDrawingCache()
方法。这将为您提供组合位图图像。
希望这对您有所帮助。
关于android - 如何用手指在图像上删除油漆?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7185376/