gpt4 book ai didi

android - 如何在 android 中像在 Canvas 上一样为 eraserPaint 编程?

转载 作者:行者123 更新时间:2023-11-29 16:19:18 24 4
gpt4 key购买 nike

我已经实现了 Canvas 和 paint 以在 Canvas 上绘制。我可以用不同的颜色在 Canvas 上作画。

现在,如果有纯白色背景就可以了。我使用白色作为橡皮擦,效果很好。但是,如果背景上有任何图像,并且如果我选择橡皮擦(如白色),那么它就会在图像上涂上白色。

而不是我想要的是,当我选择橡皮擦时,如果背景中有任何图像,那么橡皮擦应该擦掉油漆并显示图像。 .那么anybudy可以帮助我如何实现它吗?谢谢。

编辑:我正在使用下面的代码来删除正在做的油漆。但是还是擦不掉。

case R.id.eraserBtn:
currentPaint = new Paint();
currentPaint.setAlpha(0);
currentPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
currentPaint.setAntiAlias(true);

//currentPaint.setColor(0x00000000);
currentPaint.setDither(true);
currentPaint.setStyle(Paint.Style.STROKE);
currentPaint.setStrokeJoin(Paint.Join.ROUND);
currentPaint.setStrokeCap(Paint.Cap.ROUND);
currentPaint.setStrokeWidth(3);
break;

新编辑:

 case R.id.eraserBtn:
currentPaint = new Paint();
currentPaint.setAlpha(0);
currentPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
currentPaint.setAntiAlias(true);

//currentPaint.setColor(0x00000000);
currentPaint.setDither(true);
currentPaint.setStyle(Paint.Style.STROKE);
currentPaint.setStrokeJoin(Paint.Join.ROUND);
currentPaint.setStrokeCap(Paint.Cap.ROUND);
currentPaint.setStrokeWidth(15);
break;

另一个编辑:

      while (_run){

try{
canvas = mSurfaceHolder.lockCanvas(null);
if(mBitmap == null){
mBitmap = Bitmap.createBitmap (1, 1, Bitmap.Config.ARGB_8888);
}
final Canvas c = new Canvas (mBitmap);
//canvas.drawColor(0, PorterDuff.Mode.CLEAR);
c.drawColor(0, PorterDuff.Mode.CLEAR);
//canvas.drawColor(mColor);// Edited by Shreyash
c.drawColor(mColor);

// Bitmap kangoo = BitmapFactory.decodeResource(getResources(),R.drawable.icon);
// canvas.drawBitmap (kangoo, 0, 200,null);

// works for logo
// Bitmap kangoo = BitmapFactory.decodeResource(getResources(),R.drawable.icon);
// c.drawBitmap (kangoo, 0, 200,null);

if(!(DrawingActivity.imagePath==null)){
c.drawBitmap(DrawingActivity.mBitmap, 0, 0, null);
}
commandManager.executeAll(c);
canvas.drawBitmap (mBitmap, 0, 0,null);

} finally {
mSurfaceHolder.unlockCanvasAndPost(canvas);
}
}

最佳答案

我不是很清楚你的代码。但是 setColor 对我有用。但是您可以尝试以下代码之一,虽然不是确切的解决方案,但供您引用...

  1. http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/FingerPaint.html
  2. http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/TouchPaint.html
  3. 最好的(按照我的建议):http://som-itsolutions.blogspot.com/2010/12/freeware-android-paint.html

关于android - 如何在 android 中像在 Canvas 上一样为 eraserPaint 编程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8149188/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com