我有两个图像视图,一个是图库图像,一个是第二个图像上的透明图像绘制画布,我想用手指清洁透明图像
我试图这样做 链接:https://play.google.com/store/apps/details?id=com.steam.doodle&hl=en我试过下面的代码
公共类MainActivity扩展Activity实现OnTouchListener {
ImageView image,transimage;
Paint paint;
Bitmap bitmap,resultbitmap;
Canvas canvas;
Button clear;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
image=(ImageView)findViewById(R.id.imageView1);
transimage=(ImageView)findViewById(R.id.imageView2);
//Bitmap mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.saibaba);
Bitmap mBitmap2 = BitmapFactory.decodeResource(getResources(), R.drawable.snw);
Bitmap bmOverlay = Bitmap.createBitmap(mBitmap2.getWidth(), mBitmap2.getHeight(), mBitmap2.getConfig());
Canvas canvas = new Canvas();
canvas.setBitmap(bmOverlay);
paint=new Paint();
paint.setAlpha(200);
// canvas.drawBitmap(mBitmap, 0, 0, null);
canvas.drawBitmap(mBitmap2, 0, 0, paint);
transimage.setImageBitmap(bmOverlay);
} }
如何用手指清洁画布
答案 0 :(得分:0)
你只需要在方法onDraw上设置Color = Transparent。这是经过测试的代码,并且正在运行。
@Override
protected void onDraw(Canvas canvas) {
if(isEraseMode){
paint.setColor(Color.TRANSPARENT);
canvas.drawPath(eraserPath, erasePaint);
//canvas.save();
}else{
canvas.drawPath(path, paint);
canvas.restore();
}
canvas.drawPath(path, paint);
super.dispatchDraw(canvas);
}
希望这会对你有所帮助.. :)