可以任何身体告诉我擦除图像上的油漆,在我的应用程序中我准备了手指画在图像上,如果我想要擦除它的颜色,在图像上获得黑色而不是擦除图像.我的代码是
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);
}
Run Code Online (Sandbox Code Playgroud)
用于擦除油漆
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
Run Code Online (Sandbox Code Playgroud)
您应该在放置在原始位图上的透明自定义视图上绘制,而不是修改orignal.这将保持简单.为此,你可以做到
<RelativeLayout ....>
<ImageView ......set original bitmap to this/>
<CustomView ...... draw on this, you can erase too./>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
为了获得修改后的位图,请调用该getDrawingCache()方法RelativeLayout.这将为您提供组合的位图图像.
希望这可以帮助.
| 归档时间: |
|
| 查看次数: |
5044 次 |
| 最近记录: |