Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# image ImageProcessing , +
i want to apply undo and redo operations on button in a photo editing application in c# programming , so that when i click undo the action on image in pictureBox is retrieved.
any one know how to apply that?
Posted 20-Jun-11 6:51am
asma89396
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

This s[^] has an undo implementation. You could consider using the logic behind this.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

It really depends on how you've written your application. One way to do this is to apply a command pattern to the application where each action on your image is applied as a command. Undoing the operation would remove the last command, and redoing it would reapply the last command.
 
If that infrastructure is too complicated, you can apply a simple undo/redo mechanism by storing the image at each action point and then undo/redo based off that. I wouldn't recommend this option though because it is incredibly memory intensive as you will be storing multiple versions of the same image.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

There are two ways to do undo/redo. Both involve an undo stack.
 
In the first, you simply put the state before the action on the stack. This is very easy, but can get memory intensive quickly, particularly for an image editor where the state is an image which can be megabytes in size.
 
In the second, what you put on the stack is the action that would need to be taken in order to return to the previous state. This is generally smaller (and is no larger, as in the worst case, for example applying a full-image filter, the action is simply to overwrite the entire state). However, for image editing it can be hard to formulate a simple inverse for most of the actions that you are likely to want to do.
 
A decent compromise between the two is to store the part of the image which is within the bounding rectangle of what the action affected (and the bounding box itself, of course). For most operations this will be only a small part of the image.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Yes. You need to program this feature from scratch. For example, store a circular ring of few past steps in editing in a queue of images. For example, if you use bitmap, use System.Collections.Generic.Queue<Bitmap>. Each time you commit the change, push newly modified image and remove the oldest one. Retrieve the old image some steps back on user's "Undo". This is the simplest approach, you could devise some more advanced.
 
—SA
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 George Jonsson 215
1 Kornfeld Eliyahu Peter 169
2 OriginalGriff 120
3 PIEBALDconsult 110
4 BillWoodruff 85
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 21 Jun 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100