Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Undoing a pen and brush on a canvas?

Posted on 1998-04-26
9
Medium Priority
?
513 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Accepted Solution

by:
KirkGray earned 40 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

610 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