0

How can one save drawing on canvas in android, so that it could be restored at some point in future? For example, I save current drawing on canvas, then draw something else, and after that restore canvas to the previous saved state.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
Yury Pogrebnyak
  • 4,093
  • 9
  • 45
  • 78

2 Answers2

1

You have to store the model data separately. In draw method you only define how to draw this data. Depending on the situation you can set a flag and in draw, draw the appropriate model.

You also can save the canvas as a file / bitmap, see for example this: Image on canvas to JPEG file

Community
  • 1
  • 1
User
  • 31,811
  • 40
  • 131
  • 232
1

Canvas draws on Bitmap so if that is sufficient, then save your bitmap to file. But if you want to save all user "strokes", you need to record it separately and then replay once loaded.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
  • i want to draw speedometer lines, when the speed increases to some limit i want to change the color of the lines, to other color, but the problem is that all the previous lines colors also getting changed, but i d'nt want to change the previous lines color, it should be same the previous. – Deepak Sep 08 '14 at 07:34
  • cases are like : if speed less then 100 km, then lines color should be b green if speed increases 150 then it should be yellow, or above 200 it should be red, the lines color is getting changed but all the lines getting changed to one color either green, yellow or read,, the previous should not be changed..???? please help> – Deepak Sep 08 '14 at 07:37