Redraw On Touch - android

Hello All,
I have erased an image using mPaint.setXfermode(new PorterDuffXfermode(Mode.DST_OUT)); on touch events, now I want to undo this drawing (basically removing the path which were drawn earlier) on touch events. I don't want to draw the whole path at once instead clear the path point wise as finger move above these paths. I have stored all tha paths in an array list. Any Idea how can I do this. I'm able to remove the whole path but not point wise redrawing.

Related

How to delete first point from path which is drawn to android canvas

I want to draw a line on android canvas. This line must follow user's finger. I want to remove first point of path continuously. How to accomplish this. Thank you.
Save all the points in a linkedlist. Redraw the path every time a point is added/removed (i.e clear the screen, draw line from p0 to p1, from p1 to p2...). After a point is added and there are already say 100 points then remove the first to keep the list down to a fixed size.

Drawing and storing a user's touch path in libgdx

I'm struggling with something I would expect to be straight forward with libgdx.
In short this is a "finger paint" app where I want to draw a path of a certain width where the user touches the screen.
I've earlier done this by using a plain Android android.view.View. I had a android.graphics.Path in which I stored the coordinates of the user's current touch. In the onDraw() method of the view I drew the path to the android.graphics.Canvas. Whenever the user released a finger I drew the path to an offline canvas/android.graphics.Bitmap which also was drawn in the onDraw() method. Plain and simple.
How can that be done using libgdx?
I have tried using a com.badlogic.gdx.graphics.Pixmap that I can draw a line to whenever the user moves a finger. This works well except the fact that I'm unable to control the witdh of the line using Gdx.gl.glLineWidth(). I know I can draw a rectangle instead of a line to set the width, but Pixmap doesn't seem to have any means of rotating, so I don't see how this can be done.
I can use a com.badlogic.gdx.graphics.glutils.ShapeRenderer for drawing lines (or rectangles) in com.badlogic.gdx.Screen.render(). As far as I can see I then need to store every single touch point of the current touch, and then draw all lines on render. Whenever the user relases a finger I guess I can store the screen as-is with something like com.badlogic.gdx.utils.ScreenUtils.getFrameBufferPixmap(). Hopefully there is a easier way to achieve what I want.
I ended up drawing circles on a pixmap where the line should be:
One circle on touchDown
Several circles from last touch point to next touch point reported to touchDragged
I'm not very happy with this solution, but it kinda works.
Maybe you can calculate line dot coordinates manually and use triangles to draw them on pixmap? Like use 2 triangles to form (rotated) box?

How to clear just the last drawn path not the whole view

I have a view on which I am drawing some text using Path on canvas. Now I need to clear only the last drawn path i.e. drawn without clearing the whole view because I want to further redraw and re-clear path.
I have already used draw.Color(Color.BLACK) but this turns my whole screen into black, but I need to clear only the last drawn path not the whole view.

How to add undo/redo feature into android drawing app?

I want to add undo & redo feature to the finger paint, does anyone got ideas?
it is suitable to use in finger paint of android API demos.
You want to record your drawing steps, such as using an array of Paths every time a new path is drawn. When the undo button is pressed, you decrease your "draw counter" by one and redraw all the paths up to your "draw counter". When you redo, increase your "draw counter" by one and redraw all the paths up to the counter (or end of the array, naturally!). And after undoing and then drawing anew, remove the later entries from the draw array.

Antialiasing and updating a path lead to thicker lines than expected

The problem is pretty complicated to explain but here goes:
I'm making a paint program that draws paths onto a canvas with textured background. Each stroke is stored as a path that updates as the user moves the stylus across the screen. When the path is updated I call drawpath on the canvas. The problem is that on each move event, the path is drawn over the existing line on the canvas, so the antialiasing on it darkens the existing line and make it appear thicker and jaggier than expected.
I had a solution where I store the older canvas (the one without the active path) and keep another transparent canvas on top of that. I would clear the top canvas and redraw the path on each move event, and then draw both canvases together. BUT that makes the program so slow that the paths look terrible - you can tell the drawing is lagging way behind the stylus movements.
Is there any way to make either A) drawing / clearing multiple canvases faster or B) make antialiasing not mess up on multiple redraws?
Figured out.
It was so simple I can't believe I got stuck on it.
The "canvas" used in onDraw() is automatically erased every time, so I just called canvas.drawPath() with the currently updating path in the onDraw() function, at no extra cost.

Categories

Resources