Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change default erase color in paint application in Android?

I make an Application in which I want to erase drawing lines with event. For this I used

mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));

but at the time of erasing a line, that line becomes black first then erased. I want a transparent color for erasing a drawing a path.

like image 548
user1287756 Avatar asked Mar 30 '12 06:03

user1287756


People also ask

How do I change the color of my paint on Android?

What you need to do is set the color between drawing. paint. setColor(color. RED); // Will apply to first path.

What is Paint class in Android?

The Paint class holds the style and color information about how to draw geometries, text and bitmaps.

What is paint Anti_alias_flag?

ANTI_ALIAS_FLAG. Paint flag that enables antialiasing when drawing.


1 Answers

I have gone through the FingerPaint.java from APIDemos i.e android-sdk\samples\android-17\ApiDemos

and modified

@Override
protected void onDraw(Canvas canvas) {
    canvas.drawColor(0xFFAAAAAA);

    canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);

    canvas.drawPath(mPath, mPaint);
}

to

@Override
protected void onDraw(Canvas canvas) {
   canvas.drawColor(0xFFAAAAAA);

   canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);

   mCanvas.drawPath(mPath, mPaint);  // this line changed 
                                     // mCanvas is Canvas variable which is
                                     // initialized in onSizeChanged()
}

Now it is not drawing a black color while erasing, everything works fine. Not sure it is 100% proper answer but it works for me.

like image 160
Balaji Avatar answered Oct 06 '22 01:10

Balaji