Solved

Undoing a pen and brush on a canvas?

Posted on 1998-04-26
9
492 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

932 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

15 Experts available now in Live!

Get 1:1 Help Now