HOWTO: Rotate all Images in a WorkspaceViewer with Only One Undo


Please note that using the Images collection of a WorkspaceViewer or AnnotateViewer is (like using an ImageCollection directly) a very memory inefficient approach. Each image in an ImageCollection requires a contiguous block of memory height * width * pixel_depth and all need to be in memory at once.

Please consider using the DocumentViewer or DocumentAnnotationViewer instead

Original Content

The following code will rotate all of the images in a WorkspaceViewer, while only setting a single Undo. The trick is to add the modified image to a separate Workspace object, then replace each image in the WorkspaceViewer.

Note that this is easy for commands that return a new image, such as the RotateCommand used here. Check the InPlaceProcessing property of a command to find out if it returns a new image or modifies the image in place. For commands to use in place processing you should use the command's ApplyToImage method directly with the images in the WorkspaceViewer. This will change the image without adding undo entries.


RotateCommand cmd = new RotateCommand(180,InterpolationMode.BiLinear,Color.White);
Workspace ws = new Workspace();
ws.AutoDispose = false;

foreach (AtalaImage img in this.workspaceViewer1.Images)

this.workspaceViewer1.Undos.Add("Flip", true);

for (int i = 0; i < ws.Images.Count; i++)
    this.workspaceViewer1.Images[i] = ws.Images[i];

this.workspaceViewer1.Images.Current = this.workspaceViewer1.Images[0];


Dim cmd As RotateCommand =  New RotateCommand(180,InterpolationMode.BiLinear,Color.White) 
Dim ws As Workspace =  New Workspace() 
ws.AutoDispose = False
Dim img As AtalaImage
For Each img In Me.workspaceViewer1.Images
Me.workspaceViewer1.Undos.Add("Flip", True)
Dim i As Integer
For  i = 0 To  ws.Images.Count- 1  Step  i + 1
    Me.workspaceViewer1.Images(i) = ws.Images(i)
Me.workspaceViewer1.Images.Current = Me.workspaceViewer1.Images(0)

Original Article:
Q10138 - HOWTO: Rotating all images in a WorkspaceViewer with only one Undo.