Page 1 of 1

Saving and restoring a canvas content

PostPosted: Tue Sep 18, 2012 1:13 pm
by elfdav
Hi guys,

I'm writing a little paint-like software.

Is there a simple way to save and restore a canvas content to a given file format like .png or jpg ?

I saw methods called "savecanvas" and "restorecanvas" but i got some difficulties to use that.

The goal is pretty simple: i would like to draw something into my canvas actor, then save it. After that the user will be free to restore it to continue its draw.

Thanks for your answers and suggestions

David

Re: Saving and restoring a canvas content

PostPosted: Tue Sep 18, 2012 8:20 pm
by skydereign
As you mentioned in your pm, savecanvas doesn't create an actual file. Because of this it can only be used for undo type functionality. Also canvas doesn't have a built in way of accessing individual pixels in the canvas (which you need to be able to write it). So you need to create a large array to represent the drawable surface of the canvas. And when you would change a pixel on the canvas, you change a pixel in the array. You won't be able to make a png from this, as png files are really complex, and we don't have access to the proper library, but bmp is very simple. If you search the forums there are plenty of good examples.