Solved

Undoing a pen and brush on a canvas?

Posted on 1998-04-26
9
502 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

730 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