-1

I am using canvas.

I am trying to draw line and erase previous line simultaneously but it's hidden behind the drawn line. So I want to draw line continuously and erase previous one. What thing is missing, and how can I solve that? Any help is welcome.

Here is a screen of the application

public class DrawView extends View {
Paint paint = new Paint();
Path mPath, mPathErase;
Paint PaintWhite = new Paint();
float Rectpx, RectgetScanBarWidth, RectgetHeight;
int cnvasHight;
int cnvasWidth;


public DrawView(Context context) {
    super(context);
    paint.setColor(Color.GREEN);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeJoin(Paint.Join.MITER);
    paint.setStrokeWidth(2f);
    mPath = new Path();
    mPathErase = new Path();

    PaintWhite.setColor(Color.WHITE);
    PaintWhite.setStyle(Paint.Style.STROKE);
    PaintWhite.setStrokeJoin(Paint.Join.MITER);
    PaintWhite.setStrokeWidth(4f);


}


public ContextObject plotingProcedure(ContextObject drow, float py) {
    System.out.println("counter:=" + Float.parseFloat(drow.getCounter().toString()) + " PX:-" + drow.getPx() + " Py:-" + drow.getPy());
    Rectpx = drow.getPx();
    RectgetScanBarWidth = drow.getScanBarWidth();
    RectgetHeight = drow.getHeight();
    drow.setPx(Float.parseFloat(drow.getCounter().toString()));
    drow.setPy(py);
    System.out.println("Rect Dim" + Rectpx + " , " + RectgetScanBarWidth + " , " + RectgetHeight);
    mPath.moveTo(drow.getOpx(), drow.getOpy());
    mPath.lineTo(drow.getPx(), drow.getPy());

    drow.setOpx(drow.getPx());
    drow.setOpy(drow.getPy());

    if (drow.getOpx() > drow.getWidth()) {
        drow.setPx(0);
        drow.setOpx(0);
        drow.setCounter(0d);
    } else {
        System.out.println("counter after:======" + drow.getCounter());
        drow.setCounter(drow.getCounter() + drow.getSpeed());
    }
    drow.setCurrentsample(drow.getCurrentsample() + 1);


    invalidate();
    return drow;
}

@Override
public void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    paint.setColor(Color.BLUE);
    paint.setStrokeWidth(5);
    canvas.drawRect(Rectpx, 0, Rectpx + RectgetScanBarWidth, RectgetHeight, paint);
    paint.setColor(Color.GREEN);
    paint.setStrokeWidth(5);
    canvas.drawPath(mPath, paint);
}

public int getCanvasHeigt() {
    return cnvasHight;
}

public void setCanvasHeigt(int cnvasHight) {
    this.cnvasHight = cnvasHight;
}

public int getCanvasWidth() {
    return cnvasWidth;
}

public void setCanvasWidth(int width) {
    this.cnvasWidth = width;
}

}

Marko Popovic
  • 3,999
  • 3
  • 22
  • 37
Ankit Mahadik
  • 2,275
  • 22
  • 35

1 Answers1

-1

You need to clear your canvas before drawing a new line so u can use the approach illustrated in the Link

Community
  • 1
  • 1