Image viewer control.
public ImageViewer ImageViewer { get; }
The ImageViewer control used to view the main content of the document.
ImageViewer is initialized during CreateDocumentViewer. A new instance of ImageViewer is created and set in this property. The control is added as a child to DocumentViewerCreateOptions.ViewContainer and initialized as follows:
| Member | Description |
|---|---|
|
1 |
|
|
White color |
|
|
4, 4, 4, 4 |
|
|
true |
|
|
ImageViewer.Tag |
Set to the owner DocumentViewer. Be careful not to modify this value in your application. |
In addition to the above, the document viewer subscribes to the PostRenderItem event to render the current text selection used by DocumentViewer.Text, the annotations for the pages used by Annotations and any optional debugging rendering done by DocumentViewer.Diagnostics.
After CreateDocumentViewer returns, you can further customize or use this ImageViewer control as needed by your application.
using Leadtools;using Leadtools.Controls;using Leadtools.Document;using Leadtools.Document.Viewer;using Leadtools.Codecs;using Leadtools.Caching;using Leadtools.Annotations.Engine;using Leadtools.Ocr;// Disable the example button, this should only run onceexampleButton.Enabled = false;// Get the viewvar view = _documentViewer.View;// Get its image viewervar imageViewer = view.ImageViewer;// Hook to the PostRenderimageViewer.PostRenderItem += (sender, e) =>{// Get the image viewer item for the pagevar item = e.Item;// Get the current rectangle for the imagevar bounds = imageViewer.GetItemViewBounds(item, ImageViewerItemPart.Image, false);// Build the text we want. The page number is the item index + 1var pageNumber = imageViewer.Items.IndexOf(item) + 1;var text = "Page " + pageNumber.ToString();// Get the image transformation for this itemvar transform = imageViewer.GetItemImageTransform(e.Item);// Apply it to the contextvar gstate = e.Context.Save();using (var matrix = new System.Drawing.Drawing2D.Matrix((float)transform.M11,(float)transform.M12,(float)transform.M21,(float)transform.M22,(float)transform.OffsetX,(float)transform.OffsetY)){e.Context.MultiplyTransform(matrix);}// Render the text at the bottom of the boundsvar flags = TextFormatFlags.HorizontalCenter | TextFormatFlags.Bottom;var rc = new Rectangle((int)bounds.X, (int)bounds.Y, (int)bounds.Width, (int)bounds.Height);TextRenderer.DrawText(e.Context, text, imageViewer.Font, rc, Color.White, Color.Black, flags);e.Context.Restore(gstate);};// Invalidate so our changes take effect the first timeview.Invalidate();