Link to home
Start Free TrialLog in
Avatar of pedro1
pedro1

asked on

Undoing a pen and brush on a canvas?

At the moment I copy from the clipboard a bmp image for editing.
I can draw on the image no problem, but how do I if I make a mistake Undo the last draw or delete the 'Ink' from the bitmap. Please help.
michael.ross@cableinet.co.uk
Cheers Mike Ross
Avatar of inter
inter
Flag of Türkiye image

In my opinion, if you want to make a one step undo, copy the effected minimum rectangle to a undo buffer(i.e. another bitmap) if the user undoes just past it to its original position. There is another clear way, but coding is to much hard.(Just storing the effected pixels, in this case you should paremeterize the line for example and grab the pixels to the undo buffer)
Igor
Avatar of pedro1
pedro1

ASKER

What I would really like to do is use the pen or something like it to rub out the affected section leaving the original bitmap unaffected. Can it be done.
michael.ross@cableinet.co.uk
Cheers Mike Ross
Like Igor said, I'd copy off the bitmap for an original whenever a new action is started.  Then, you can achieve a undo brush look and feel by mapping pixels over from it whenever they are affected on the 'working' bitmap by the brush.  
ASKER CERTIFIED SOLUTION
Avatar of KirkGray
KirkGray

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yo,
sorry, KirkGray, the answer is yes.
You could do that easily if you keep two layers. The first layer contains the bitmap, the second is an empty canvas where you draw on. If you want to erase smthg, it will be erased from the second layer. Now when you want to save or copy the modified bitmap, stretchdraw your second layer on the bitmap, empty your second layer and do business as usual.

Slash/d003303
That would work, but I think it's splitting hairs a bit disagreeing with me like that.  

I said: "you must save it in someway before it was modified".  Call it a layer or a snapshot or an Undo Image, you still MUST save the old image in someway in order to restore it.

pedro1: Have you considered using a metafile (in short: A metafile produces a drawing by storing the graphics commands used to create it like *.WMF format)   This format is very flexable and would allow multiple undo's.
Hi KirkGray,
your're absolutely right, I used the wrong words, sorry. I was just misunderstanding your way to answer. The answer "No" in the exact context of the question is right, and I wasn't reading any furher through the comment below that describes the way how to acheive a real undo.
When I read "No" I thought WHY ? Nothing is realy impossible. Maybe not the way like it was thought in the question, maybe completely different, but the result has to be the same. Many people who ask questions in this forum are relatively new in Delphi. So giving an answer by saying "No" instead of saying "No, not this way. But..." is correct, but would not be fair. Unfortunately, some guys do that, so I had to point that out. Good to see that you are not one of those.

Now, back to the question. A Metafile would be more flexible. It depends on your needs if you want to use it or just paint on a canvas. That's like you use CorelDraw for vector graphics (would be the metafile thing) or PhotoPaint for pixel graphics (the canvas thing).

Slash/d003303
Avatar of pedro1

ASKER

As you have probably guessed I am new to delphi so am unsure about this metafile thing. One thing I have realised so far is that BMP images are saving out as about 400kb Way to big . Is there a way to shrink them e.g. compress them. Or does the wmf format make a smaller file.
I am going to try and paste the bmp to a clipboard before the edit and supply an undo button to restore it. Does this sound like the best way to do this.
Cheers MIKE Ross
A most polite reply d003303,  I wish there was more like U about.