/// <summary>
/// This example demonstrates how to process an image with annotations and undo changes in image and annotations.
/// </summary>
public void ImageAndAnnotationsUndoManagerExample()
{
// create an image collection
Vintasoft.Imaging.ImageCollection images =
new Vintasoft.Imaging.ImageCollection();
// add image to the image collection
images.Add(@"..\..\Resources\Image.png");
Vintasoft.Imaging.VintasoftImage image = images[0];
// create the annotation data controller for image collection
Vintasoft.Imaging.Annotation.AnnotationDataController annotationDataController =
new Vintasoft.Imaging.Annotation.AnnotationDataController(images);
// get reference to the annotation data collection of image
Vintasoft.Imaging.Annotation.AnnotationDataCollection annotationDataCollection =
annotationDataController.GetAnnotations(image);
// get reference to the annotation view collection of image
Vintasoft.Imaging.Annotation.UI.AnnotationViewCollection annotationViewCollection =
new Vintasoft.Imaging.Annotation.UI.AnnotationViewCollection(annotationDataCollection);
// show information about image and annotations
ShowInfo(image, annotationDataCollection);
// create an instance of undo manager
Vintasoft.Imaging.Undo.UndoManager undoManager =
new Vintasoft.Imaging.Undo.UndoManager();
// create the image resize command
Vintasoft.Imaging.ImageProcessing.ResizeCommand resizeCommand =
new Vintasoft.Imaging.ImageProcessing.ResizeCommand();
// create the undo monitor for the image resize command
using (Vintasoft.Imaging.Undo.UndoMonitor resizeCommandUndoMonitor =
new Vintasoft.Imaging.Undo.ImageProcessingUndoMonitor(undoManager, resizeCommand))
{
// create the undo monitor for annotations
using (Vintasoft.Imaging.Undo.UndoMonitor annotationUndoMonitor =
new Vintasoft.Imaging.Annotation.UI.Undo.AnnotationViewCollectionUndoMonitor(
undoManager, annotationViewCollection))
{
// Step 1
// create a rectangle annotation
Vintasoft.Imaging.Annotation.RectangleAnnotationData rectangleAnnotationData =
new Vintasoft.Imaging.Annotation.RectangleAnnotationData();
rectangleAnnotationData.Location = new System.Drawing.PointF(60, 110);
rectangleAnnotationData.Size = new System.Drawing.SizeF(100, 38);
// add the rectangle annotation to the image
annotationDataCollection.Add(rectangleAnnotationData);
// show information about image and annotations
ShowInfo(image, annotationDataCollection);
// undo one step (Step 1)
undoManager.Undo(1);
// show information about image and annotations
ShowInfo(image, annotationDataCollection);
// Step 2: resize image
resizeCommand.Width = 550;
resizeCommand.Height = 450;
resizeCommand.ExecuteInPlace(image);
// show information about image and annotations
ShowInfo(image, annotationDataCollection);
// Step 3
// change an existing annotation
Vintasoft.Imaging.Annotation.AnnotationData annotationData = annotationDataCollection[0];
annotationData.Location = new System.Drawing.PointF(15, 10);
// show information about image and annotations
ShowInfo(image, annotationDataCollection);
// undo two steps (Step 3 and Step 2)
undoManager.Undo(2);
// show information about image and annotations
ShowInfo(image, annotationDataCollection);
// redo one step (Step 2)
undoManager.Redo(1);
// show information about image and annotations
ShowInfo(image, annotationDataCollection);
}
}
}
/// <summary>
/// Shows information about image and annotations.
/// </summary>
/// <param name="image">Image.</param>
/// <param name="annotationDataCollection">Annotation data collection.</param>
public void ShowInfo(
Vintasoft.Imaging.VintasoftImage image,
Vintasoft.Imaging.Annotation.AnnotationDataCollection annotationDataCollection)
{
// show information about image
System.Console.WriteLine("Image: {0}x{1} PixelFormat:{2}", image.Width, image.Height, image.PixelFormat);
// show information about annotations
System.Console.WriteLine("Annotation count: {0}", annotationDataCollection.Count);
foreach (Vintasoft.Imaging.Annotation.AnnotationData annotationData in annotationDataCollection)
{
System.Type annotationDataType = annotationData.GetType();
System.Console.WriteLine("\tType:{0} Location:{1} Size:{2}", annotationDataType.Name,
annotationData.Location, annotationData.Size);
}
}
/* This code example produces the following output:
Image: 500x418 PixelFormat:Bgr24
Annotations count: 2
Type:PolygonAnnotationData Location:{X=26,00019, Y=22,55438} Size:{Width=60,77151, Height=61,08478}
Type:LineAnnotationData Location:{X=114,9647, Y=15,34951} Size:{Width=0, Height=104,6273}
Image: 500x418 PixelFormat:Bgr24
Annotations count: 3
Type:PolygonAnnotationData Location:{X=26,00019, Y=22,55438} Size:{Width=60,77151, Height=61,08478}
Type:LineAnnotationData Location:{X=114,9647, Y=15,34951} Size:{Width=0, Height=104,6273}
Type:RectangleAnnotationData Location:{X=60, Y=110} Size:{Width=100, Height=38}
Image: 500x418 PixelFormat:Bgr24
Annotations count: 2
Type:PolygonAnnotationData Location:{X=26,00019, Y=22,55438} Size:{Width=60,77151, Height=61,08478}
Type:LineAnnotationData Location:{X=114,9647, Y=15,34951} Size:{Width=0, Height=104,6273}
Image: 550x450 PixelFormat:Bgr24
Annotations count: 2
Type:PolygonAnnotationData Location:{X=26,00019, Y=22,55438} Size:{Width=60,77151, Height=61,08478}
Type:LineAnnotationData Location:{X=114,9647, Y=15,34951} Size:{Width=0, Height=104,6273}
Image: 500x418 PixelFormat:Bgr24
Annotations count: 2
Type:PolygonAnnotationData Location:{X=26,00019, Y=22,55438} Size:{Width=60,77151, Height=61,08478}
Type:LineAnnotationData Location:{X=114,9647, Y=15,34951} Size:{Width=0, Height=104,6273}
Image: 550x450 PixelFormat:Bgr24
Annotations count: 2
Type:PolygonAnnotationData Location:{X=26,00019, Y=22,55438} Size:{Width=60,77151, Height=61,08478}
Type:LineAnnotationData Location:{X=114,9647, Y=15,34951} Size:{Width=0, Height=104,6273}
*/