Undo drawing

I am trying to add an undo feature to part of a drawing module which I thought would be straight forward…
I have a picture array that I store the current image and when an addition is made to the drawing I add a picture to the array.
Problem is when I do this the whole array gets updated with the new image? How do I just put an instance in the array that isn’t updated?

hey can you share some code or pseudo code to understand your code structure and help you…

Mapimage is the picture property that is drawn to in the paint event.
UndiMapimage() is the picture array

In the Pointerup event after drawing on the canvas I add the updated image to
UndoMapImage.Add(MapImage)

You need to clone the picture before you add it to the array otherwise you will just be adding a reference to the same picture which will always contain the latest content.

One way to clone is to create a new picture and draw the source picture into it.

1 Like

if you have MBS

UndoMapImage.Add(MapImage.clonembs)

if not

var mapimagecopy as new picture (MapImage.width,MapImage.height)
mapimagecopy.graphics.drawpicture mapimage,0,0
UndoMapImage.Add(MapImage)
1 Like

Thanks both of those worked