Can I serialize the paths drawn on the canvas to redraw the paths when the application restarts

I have an application that uses a canvas to draw a custom lettering. I serialized the paths in an external file and saved it to the SD card. when the user starts the application again, and then by pressing the (ReDraw) button, I want the saved paths to be redrawn on the canvas. I can not redraw the paths. I extract the paths from the file during debugging and check it out. But I have no idea why the paths are not redrawn. Please help.

+6
source share
1 answer

I used the link another question here I made a few changes, and it worked pretty well for me.

To understand, we can think that we just need to save 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 the string.
Actions in this case: lineTo, moveTo, quadTo, reset, and the points are 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 do not need points, and for others we need one point (x, y).
We may think that actions are keys and {arrayX [], arrayY []} are the values ​​for the action. For actions like lineTo and moveTo the size of arrayX [] and arrayY [] is 1, and for quadTo the size is 2, and for reset the size is 0 (or we can have both arrays null), because in this case we need no points. We just need to be careful when retrieving the point values ​​from the array corresponding to the Action key. when the action is lineTo, we just draw the path on the canvas. Thanks to Krishna

+5
source

Source: https://habr.com/ru/post/905804/


All Articles