Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding Undo and Deletion to FingerPaint.java
    primarykey
    data
    text
    <p>I have worked on the fingerpaint class before and I was very much comfortable but this time I found myself in deep trouble implementing both these functionalities of Undo and deletion</p> <p>This is my drawing view</p> <pre><code>public class MyView extends View { private Bitmap mBitmap; private Canvas mCanvas; private Path mPath; private Paint mBitmapPaint; public MyView(Context c) { super(c); mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); mCanvas = new Canvas(mBitmap); mPath = new Path(); mBitmapPaint = new Paint(Paint.DITHER_FLAG); } @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); } @Override protected void onDraw(Canvas canvas) { /*canvas.drawColor(Color.WHITE); canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);*/ for (int i=0;i&lt;paths.size();i++){ canvas.drawPath(paths.get(i).path, paths.get(i).paint); } canvas.drawPath(mPath, mPaint); } private float mX, mY; private static final float TOUCH_TOLERANCE = 4; private void touch_start(float x, float y) { if ( erase == true ) { mPath.reset(); } undonePaths.clear(); mPath.moveTo(x, y); mX = x; mY = y; } private void touch_move(float x, float y) { float dx = Math.abs(x - mX); float dy = Math.abs(y - mY); if (check == 1 || (selectedId == ERASE_MENU_ID) ) { if (dx &gt;= TOUCH_TOLERANCE || dy &gt;= TOUCH_TOLERANCE) { mPath.quadTo(mX, mY, (x + mX)/2, (y + mY)/2); mX = x; mY = y; mCanvas.drawPath(mPath, mPaint); } } if(selectedId == ERASE_MENU_ID) { mCanvas.drawPath(mPath, mPaint); mPath=new Path(); mX = x; mY = y; mPath.moveTo(x, y); } } public void onClickUndo () { if (paths.size()&gt;0) { paths.remove(paths.size()-1); invalidate(); } else { } //toast the user } private void touch_up() { mCanvas.drawPath(mPath, mPaint); MyDataHolder md=new MyDataHolder(); md.paint=mPaint; md.path=mPath; paths.add(md); mPath=new Path(); } @Override public boolean onTouchEvent(MotionEvent event) { float x = event.getX(); float y = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN : touch_start(x, y); invalidate(); break; case MotionEvent.ACTION_MOVE : touch_move(x, y); invalidate(); break; case MotionEvent.ACTION_UP : touch_up(); invalidate(); break; } return true; } } </code></pre> <p>Now the problem is when I change mPaint's mode to clear</p> <pre><code> erase=true; mPaint.setXfermode(null); mPaint.setStrokeWidth(25.0f); //mPaint.setColor(Color.TRANSPARENT); mPaint.setXfermode(new PorterDuffXfermode(Mode.CLEAR)); </code></pre> <p>every drawn path turns black with 25 width somebody suggested that I am using same paint so I made a wrapper class to store paint and path object but it's not working.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload