/// <summary>
/// This example demonstrates how to process an image and undo changes in image.
/// </summary>
public static void ImageUndoManagerExample()
{
// 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];
// show information about image
ShowInfo(image);
// 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 image change pixel format command
Vintasoft.Imaging.ImageProcessing.ChangePixelFormatCommand changePixelFormatCommand =
new Vintasoft.Imaging.ImageProcessing.ChangePixelFormatCommand();
// create the undo manager for image change pixel format command
using (Vintasoft.Imaging.Undo.UndoMonitor changePixelFormatCommandUndoMonitor =
new Vintasoft.Imaging.Undo.ImageProcessingUndoMonitor(undoManager, changePixelFormatCommand))
{
// Step 1: change pixel format to grayscale
changePixelFormatCommand.PixelFormat = Vintasoft.Imaging.PixelFormat.Gray8;
changePixelFormatCommand.ExecuteInPlace(image);
// show information about image
ShowInfo(image);
// undo one step (Step 1)
undoManager.Undo(1);
// show information about image
ShowInfo(image);
// Step 2: resize image
resizeCommand.Width = 750;
resizeCommand.Height = 350;
resizeCommand.ExecuteInPlace(image);
// show information about image
ShowInfo(image);
// Step 3: change pixel format to Bgr48
changePixelFormatCommand.PixelFormat = Vintasoft.Imaging.PixelFormat.Bgr48;
changePixelFormatCommand.ExecuteInPlace(image);
// show information about image
ShowInfo(image);
// undo two steps (Step 3 and Step 2)
undoManager.Undo(2);
// show information about image
ShowInfo(image);
// redo one step (Step 2)
undoManager.Redo(1);
// show information about image
ShowInfo(image);
}
}
}
/// <summary>
/// Shows information about image.
/// </summary>
/// <param name="image">Image.</param>
public static void ShowInfo(
Vintasoft.Imaging.VintasoftImage image)
{
// show information about image
System.Console.WriteLine("Image: {0}x{1} PixelFormat:{2}", image.Width, image.Height, image.PixelFormat);
}
/* This code example produces the following output:
Image: 500x534 PixelFormat:Bgr24
Image: 500x534 PixelFormat:Gray8
Image: 500x534 PixelFormat:Bgr24
Image: 750x350 PixelFormat:Bgr24
Image: 750x350 PixelFormat:Bgr48
Image: 500x534 PixelFormat:Bgr24
Image: 750x350 PixelFormat:Bgr24
*/
''' <summary>
''' This example demonstrates how to process an image and undo changes in image.
''' </summary>
Public Shared Sub ImageUndoManagerExample()
' create an image collection
Dim images As New Vintasoft.Imaging.ImageCollection()
' add image to the image collection
images.Add("..\..\Resources\Image.png")
Dim image As Vintasoft.Imaging.VintasoftImage = images(0)
' show information about image
ShowInfo(image)
' create an instance of undo manager
Dim undoManager As New Vintasoft.Imaging.Undo.UndoManager()
' create the image resize command
Dim resizeCommand As New Vintasoft.Imaging.ImageProcessing.ResizeCommand()
' create the undo monitor for the image resize command
Using resizeCommandUndoMonitor As Vintasoft.Imaging.Undo.UndoMonitor = New Vintasoft.Imaging.Undo.ImageProcessingUndoMonitor(undoManager, resizeCommand)
' create the image change pixel format command
Dim changePixelFormatCommand As New Vintasoft.Imaging.ImageProcessing.ChangePixelFormatCommand()
' create the undo manager for image change pixel format command
Using changePixelFormatCommandUndoMonitor As Vintasoft.Imaging.Undo.UndoMonitor = New Vintasoft.Imaging.Undo.ImageProcessingUndoMonitor(undoManager, changePixelFormatCommand)
' Step 1: change pixel format to grayscale
changePixelFormatCommand.PixelFormat = Vintasoft.Imaging.PixelFormat.Gray8
changePixelFormatCommand.ExecuteInPlace(image)
' show information about image
ShowInfo(image)
' undo one step (Step 1)
undoManager.Undo(1)
' show information about image
ShowInfo(image)
' Step 2: resize image
resizeCommand.Width = 750
resizeCommand.Height = 350
resizeCommand.ExecuteInPlace(image)
' show information about image
ShowInfo(image)
' Step 3: change pixel format to Bgr48
changePixelFormatCommand.PixelFormat = Vintasoft.Imaging.PixelFormat.Bgr48
changePixelFormatCommand.ExecuteInPlace(image)
' show information about image
ShowInfo(image)
' undo two steps (Step 3 and Step 2)
undoManager.Undo(2)
' show information about image
ShowInfo(image)
' redo one step (Step 2)
undoManager.Redo(1)
' show information about image
ShowInfo(image)
End Using
End Using
End Sub
''' <summary>
''' Shows information about image.
''' </summary>
''' <param name="image">Image.</param>
Public Shared Sub ShowInfo(image As Vintasoft.Imaging.VintasoftImage)
' show information about image
System.Console.WriteLine("Image: {0}x{1} PixelFormat:{2}", image.Width, image.Height, image.PixelFormat)
End Sub
' This code example produces the following output:
'
' Image: 500x534 PixelFormat:Bgr24
' Image: 500x534 PixelFormat:Gray8
' Image: 500x534 PixelFormat:Bgr24
' Image: 750x350 PixelFormat:Bgr24
' Image: 750x350 PixelFormat:Bgr48
' Image: 500x534 PixelFormat:Bgr24
' Image: 750x350 PixelFormat:Bgr24
'
/// <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}
*/
''' <summary>
''' This example demonstrates how to process an image with annotations and undo changes in image and annotations.
''' </summary>
Public Sub ImageAndAnnotationsUndoManagerExample()
' create an image collection
Dim images As New Vintasoft.Imaging.ImageCollection()
' add image to the image collection
images.Add("..\..\Resources\Image.png")
Dim image As Vintasoft.Imaging.VintasoftImage = images(0)
' create the annotation data controller for image collection
Dim annotationDataController As New Vintasoft.Imaging.Annotation.AnnotationDataController(images)
' get reference to the annotation data collection of image
Dim annotationDataCollection As Vintasoft.Imaging.Annotation.AnnotationDataCollection = annotationDataController.GetAnnotations(image)
' get reference to the annotation view collection of image
Dim annotationViewCollection As New Vintasoft.Imaging.Annotation.UI.AnnotationViewCollection(annotationDataCollection)
' show information about image and annotations
ShowInfo(image, annotationDataCollection)
' create an instance of undo manager
Dim undoManager As New Vintasoft.Imaging.Undo.UndoManager()
' create the image resize command
Dim resizeCommand As New Vintasoft.Imaging.ImageProcessing.ResizeCommand()
' create the undo monitor for the image resize command
Using resizeCommandUndoMonitor As Vintasoft.Imaging.Undo.UndoMonitor = New Vintasoft.Imaging.Undo.ImageProcessingUndoMonitor(undoManager, resizeCommand)
' create the undo monitor for annotations
Using annotationUndoMonitor As Vintasoft.Imaging.Undo.UndoMonitor = New Vintasoft.Imaging.Annotation.UI.Undo.AnnotationViewCollectionUndoMonitor(undoManager, annotationViewCollection)
' Step 1
' create a rectangle annotation
Dim rectangleAnnotationData As 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
Dim annotationData As Vintasoft.Imaging.Annotation.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)
End Using
End Using
End Sub
''' <summary>
''' Shows information about image and annotations.
''' </summary>
''' <param name="image">Image.</param>
''' <param name="annotationDataCollection">Annotation data collection.</param>
Public Sub ShowInfo(image As Vintasoft.Imaging.VintasoftImage, annotationDataCollection As Vintasoft.Imaging.Annotation.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)
For Each annotationData As Vintasoft.Imaging.Annotation.AnnotationData In annotationDataCollection
Dim annotationDataType As System.Type = annotationData.[GetType]()
System.Console.WriteLine(vbTab & "Type:{0} Location:{1} Size:{2}", annotationDataType.Name, annotationData.Location, annotationData.Size)
Next
End Sub
' 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}
'