Yury Pogrebnyak
Yury Pogrebnyak

Reputation: 4173

Android: save drawing on canvas

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.

Upvotes: 0

Views: 2088

Answers (2)

Marcin Orlowski
Marcin Orlowski

Reputation: 75635

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.

Upvotes: 1

ixx
ixx

Reputation: 32269

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

Upvotes: 1

Related Questions