I have implement the Canvas and paint to draw on canvas. i am able to do the Paint on canvas with different colour.
Now, if there is white plain background then its ok. I am using white color for Eraserand its work fine. But if there is any image on the background and if i select eraser (as like white colour) then it is being paint of white color on the image.
Instead of that i want is, While i select eraser and if there is any image in background then the eraser should erase the paint and show the image. . So can anybudy help me how to implement it ?? Thanks.
Edited: I am using below code to Erase the doing paint. But still not able to erase it.
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;
New Edited:
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;
Another Edit:
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);
}
}