The Annotation User Interface Can Be Accessed Through PageView
The ImageGear.Art.Windows.Controls namespace/assembly (including the Annotator/ToolBarAnnotator controls) is still available in ImageGear but will be removed in a future version of ImageGear. It has been replaced by the ImageGear.Windows.Controls.Art.dll. All annotation user interface functionality can now be accessed directly through the PageView control, and it is no longer necessary to use the Annotator or ToolBarAnnotator controls. This includes accessing the annotation context menu items in the new PageView context menu, which is discussed in the Context Menu section of the help file.
Annotation Mouse Tool and Mode
To access the annotation toolbar functionality in the PageView control, add a reference to ImageGear.Windows.Controls.Art.dll in your project (and distribute this assembly with your application), and set the PageView MouseTool property to an annotation mouse tool setting. For example, if you set the MouseTool property to CreateRectangleMark, you can then use the mouse to create a rectangle mark. You can set the PageView AnnotationMode property to Edit to enable editing annotations using the mouse, or you can set this property to View to disable editing annotations using the mouse.
If you do not reference ImageGear.Windows.Controls.Art.dll in your project, then the PageView AnnotationMode property will have no effect, and if the PageView MouseTool property is set to an annotation mouse tool, the behavior will be the same as setting the MouseTool property to None. The PageView AnnotationsAreAvailable method will return True if your application is referencing ImageGear.Windows.Controls.Art.dll and is able to locate it.
Annotation Mouse Tool Settings
You can use the PageView.MouseToolSettings.Annotation property to access the mouse tool settings for each mark. These annotation settings are similar to the Annotator settings, except a SelectionStyle property has been added to replace the SelectorColor and SelectorOpacity properties. The SelectionStyle property can be used to set a Style for the annotation selection rectangle, to specify its look. If you were using Annotator and setting the SelectorColor and SelectorOpacity properties, you can get the same appearance by creating a SolidColorBrush with the opacity and color, creating a Style, and adding a Setter for the Brush Stroke property, as shown below.
C# Example | ![]() |
---|---|
System.Windows.Media.Color annColor = System.Windows.Media.Color.FromArgb(myOpacity, myColor.R, myColor.G, myColor.B); System.Windows.Media.Brush annBrush = new System.Windows.Media.SolidColorBrush(annColor); Style selectStyle = new Style(typeof(System.Windows.Shapes.Rectangle)); Setter setterStroke = new Setter(System.Windows.Shapes.Rectangle.StrokeProperty, annBrush); selectStyle.Setters.Add(setterStroke); pageView.MouseToolSettings.Annotation.SelectionStyle = selectStyle; |
Also, a DefaultImage property of type ImGearPage is included in the annotation settings. By default this property is null and the behavior is the same as in Annotator (i.e., a grid with the text “No Image” appears when adding an image mark using the mouse, and a file open dialog appears after adding the image mark so you can browse to an image file to load). If this property is set as shown below, the specified image is added when you use the mouse to add an image mark.
C# Example | ![]() |
---|---|
FileStream fileContent = new FileStream("c:\\myImage.jpg", System.IO.FileMode.Open); ImGearPage page = ImGearFileFormats.LoadPage(fileContent, 0); imGearPageView.MouseToolSettings.Annotation.DefaultImage = page; |
Annotation Events
Annotator contains MouseLeftButtonDown, MouseLeftButtonUp, MouseRightButtonDown, MouseRightButtonUp, and MouseMove events, and PageView contains similar events, except they do not have an ImGearARTMark parameter. You can access the ImGearARTMark at the current mouse position by using the PageView.Display.HitTestCanvas method as shown in the following code.
C# Example | ![]() |
---|---|
Point mousePoint = e.GetPosition(pageView); if (pageView.Display != null) { int markID = -1; if (pageView.Display.ARTPage != null) { ImGearARTPage art = (ImGearARTPage)pageView.Display.ARTPage; ImGearDoublePoint[] pnts = new ImGearDoublePoint[] { new ImGearDoublePoint(mousePoint.X, mousePoint.Y), new ImGearDoublePoint(mousePoint.X - 1, mousePoint.Y), new ImGearDoublePoint(mousePoint.X + 1, mousePoint.Y), new ImGearDoublePoint(mousePoint.X - 2, mousePoint.Y), new ImGearDoublePoint(mousePoint.X + 2, mousePoint.Y), new ImGearDoublePoint(mousePoint.X, mousePoint.Y - 1), new ImGearDoublePoint(mousePoint.X, mousePoint.Y + 1), new ImGearDoublePoint(mousePoint.X, mousePoint.Y - 2), new ImGearDoublePoint(mousePoint.X, mousePoint.Y + 2) }; for (int i = 0; i < pnts.Length; i++) { markID = pageView.Display.HitTestCanvas( pnts[i], pageView, pageView.Canvas, 0, 0); if (markID >= 0) break; } |
The equivalents of the Annotator PreCreateMark, PreDeleteMark, and ModifyMark events in PageView are the MarkCreating, MarkRemoved, and MarkChanged events. The PreDeleteMark event contains a Cancel argument that is only used in Annotator when the context menu’s Delete menu item is selected. If necessary, you can achieve similar functionality in PageView by creating a custom context menu and creating/specifying your own Command for the Delete menu item. The ModifyMark event contains a ModifyReason argument. If necessary, you can achieve similar functionality in PageView by binding a DependencyProperty to an ImGearARTMark’s property and specifying a PropertyChangedCallback in the PropertyMetadata, or by adding an event handler for the mark’s PropertyChanged event.
The Mark Is Drawn Instead of a Placeholder
Previous versions of ImageGear used a placeholder mark when drawing a mark on the image; after the mark was drawn this placeholder mark was removed and the actual mark was added. Now when drawing a mark on the image, the actual mark is drawn instead of a placeholder. The previous behavior is still supported in ImageGear by setting the PageView.MouseToolSettings.Annotation.DrawPreview property to True.
Handle Size Property
The PageView.MouseToolSettings.Annotation.HandleSize property can be used to specify the size of the mark handles that appear when a mark is selected.
Using Keyboard Input for Different Annotation Resize Behavior
The Shift and Ctrl keys can be used to effect how a mark is resized. If you hold the Ctrl key while resizing a mark, then the center point of the mark will be fixed. If you hold the Shift key while resizing a mark, then the aspect ratio of the mark will be fixed. If you hold both the Ctrl and Shift keys, then the center point and aspect ratio of the mark will be fixed.