Reputation: 22493
Can any body tell me to erase the paint on the image , in my application i was prepared the finger painting on image, if i want erase the paint it,s getting black color on image instead of erasing the image. my code is
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);
}
for paint erase
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
Upvotes: 1
Views: 5280
Reputation: 1
define a temporary bitmap and canvas, then draw canvas on that temporary bitmap and pass that bitmap to onDraw your work will be done,
Upvotes: 0
Reputation: 24235
You should draw on a transparent custom view placed over the original bitmap instead of modifying the orignal. That will keep it simple. For that you can do
<RelativeLayout ....>
<ImageView ......set original bitmap to this/>
<CustomView ...... draw on this, you can erase too./>
</RelativeLayout>
For getting the modified bitmap call the getDrawingCache()
method on that RelativeLayout
. That will give you the combined bitmap image.
Hope this helps.
Upvotes: 6