Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I serialize the paths drawn on canvas for redrawing the paths on relaunch of the application

I have an application which uses the canvas to draw the scribbling done by the user. I have serialised the paths in an external file and kept it in the sd card. when user again launches the application then on a click of (ReDraw) Button I want the saved paths to be redrawn on the canvas. I am not able to redraw the paths. I am retrieving the paths from the file as I debugged and checked the same. But I don't have any idea as why the paths are not getting redrawn. Kindly help.

like image 946
nits.kk Avatar asked Jan 12 '12 09:01

nits.kk


1 Answers

I took the reference from another question here I made few modifications and it worked for me quite well.

To understand we can think we just need to store a map of Actions and Points. We need path.moveTo(int x, int y), path.lineTo(int x, int y), path.quadTo(int x1, int y1, int x2, int y2) and path.reset() methods for scribbling.
Actions in this case being: lineTo, moveTo, quadTo, reset and points being the corresponding points.

I took two arrays 1 for x and another for y. For quadTo(x1,y1,x2,y2) we need two points, for reset we need no points and for other we need a single point(x,y).
We can think actions being the keys and {arrayX[], arrayY[]} being the value for an action. For actions as lineTo and moveTo size of the arrayX[] and arrayY[] is 1 and for quadTo the size is 2 and for reset the size is 0 (or we can have both the arrays null ) as in that case we need no points. We just need to be careful while retrieving the values of the points from the array corresponding to the Action key. when action is lineTo we just draw the path on the canvas.

like image 78
nits.kk Avatar answered Nov 17 '22 19:11

nits.kk