Solved

Undoing a pen and brush on a canvas?

Posted on 1998-04-26
9
488 Views
Last Modified: 2010-04-06
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
0
Comment
Question by:pedro1
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 5

Expert Comment

by:inter
ID: 1337063
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
0
 

Author Comment

by:pedro1
ID: 1337064
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
0
 

Expert Comment

by:SQLwill
ID: 1337065
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.  
0
 

Accepted Solution

by:
KirkGray earned 20 total points
ID: 1337066
"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?"

The answer is : No.

To restore the original state of the image, you must save it in someway before it was modified.  Unless you're pen is drawing in XOR mode, then just draw the line (or whatever) again in the same color and place and presto - It's back to where it was.




0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 4

Expert Comment

by:d003303
ID: 1337067
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
0
 

Expert Comment

by:KirkGray
ID: 1337068
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.
0
 
LVL 4

Expert Comment

by:d003303
ID: 1337069
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
0
 

Author Comment

by:pedro1
ID: 1337070
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
0
 

Expert Comment

by:KirkGray
ID: 1337071
A most polite reply d003303,  I wish there was more like U about.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now