The ImageViewer rendering cycle supports full customization. The various events and their data allow for any of the following:
Add user-defined rendering code on the view or the items. For example, the LEADTOOLS annotations framework hooks to the rendering cycle to draw the annotations container on top of an item.
Perform full owner drawing of any part of the view or item. For example, the ImageViewerVirtualizer hooks to the render event to draw a place holder when the image data is not present yet.
Re-direct the rendering to an external context. For example, the ImageViewerPanControl uses redirection to duplicate the current appearance of the viewer to an external control.
The rendering cycle occurs when ImageViewer.Invalidate or ImageViewer.RenderRedirect is called due to normal control painting or a response to ImageViewer.UpdateTransform. To customize the rendering cycle, you can either subscribe to the specific event or derive from the ImageViewer and override the specific virtual method. All these methods and event use the ImageViewerRenderEventArgs class to hold the information needed.
ImageViewerRenderEventArgs contains the following:
Member | Description |
---|---|
Context |
In Windows Forms, the In JavaScript, the HTML |
PaintEventArgs |
Original Windows.Forms paint arguments if this render event is in response to |
Item |
The item being rendered or null of this part of the rendering cycle is view-specific. |
Part |
The item part being rendered or View if this part of the rendering cycle is is view-specific. |
Error |
An error that was caught during the rendering cycle. Used with the ImageViewer.RenderError event. |
ImageViewerRenderEventArgs.ClipRectangle |
Current clipping rectangle to be applied. |
The image viewer will call the virtual methods and fires the events in the order described below. Note for members, ImageViewerRenderEventArgs.Contex will point to the System.Drawing.Graphics
(in Windows.Forms) or (HTML CanvasContext2D
object for the fore canvas in JavaScript) the viewer control or the redirect target.
Method - Event | ImageViewerRenderEventArgs.Item, Part | Default Operations |
---|---|---|
ImageViewer.OnEraseBackground - ImageViewer.EraseBackground JavaScript only |
null - ImageViewerItem.View |
Erases or clears the background |
OnPreRender - PreRender |
null - ImageViewerItem.View |
Nothing. Can be used to set the context properties (for example, anti-aliasing or interpolation quality) |
OnRenderShadow - RenderShadow |
null - ImageViewerItem.View |
Renders the drop shadow of the view |
OnRenderBorder - RenderBorder |
null - ImageViewerItem.View |
Renders the border of the view |
For each item |
Loops through the items in the viewer. Only occur if the item is IsVisible, has none empty ImageSize and if it intersects with the current visible viewer surface and clipping rectangle. |
|
OnPreRenderItem - PreRenderItem |
The item - Item |
Nothing |
OnRenderItem - RenderItem |
The item - Item |
Nothing |
OnRenderBackground - RenderBackground |
The item - Item |
Fills the content of the item with the background color based on the item state |
OnRenderBorder - RenderBorder |
The item - Content |
Renders the content border using the border color based on the item state |
OnRenderShadow - RenderShadow |
The item - Image |
Renders the drop shadow around the image of the item |
OnRenderImage - RenderImage |
The item - Image |
Renders the item image |
OnRenderBorder - RenderBorder |
The item - Image |
Renders the border of the image |
OnRenderText - RenderText |
The item - Text |
Renders the text of the item |
OnPostRenderItem - PostRenderItem |
The item - Item |
Nothing |
Next item | ||
OnPostRender - PostRender |
null - ImageViewerItem.View |
Renders the floaters and regions |
OnRedirectRender - RedirectRender |
null - ImageViewerItem.View |
Nothing |
The most common custom rendering is performed by subscribing to these events:
PostRenderItem: To render extra information on top of an item
PostRender: To render extra information on top of the whole viewer
Refer to these events for an example.
To manually trigger a new rendering cycle, call ImageViewer.Invalidate to invalidate a portion of the whole surface of the viewer. This method accepts a rectangle that specifies the portion of the viewer to update for optimal speed. The InvalidateItem or InvalidateItemByIndex methods can be used to re-render a single item quickly.
Rendering of the ImageViewer control normally occurs automatically and not through any code called by the user. If an error occur, the user does not have the ability to try/catch the exception and process the error. Therefore, ImageViewer contains the RenderError events. This will occur when an error happens in the internal rendering cycle. The event uses the same ImageViewerRenderEventArgs data class, so all the usual parameters of what item and part caused the error are passed to the user. In addition, it will catch the error and set it in the ImageViewerRenderEventArgs.Error property.
The ImageViewer also supports the following operations related to rendering:
Member | Description |
---|---|
Invert |
Display all items with inverted colors |
ScreenDpi |
Update the value of the screen resolution in dots per inch |
UseDpi |
Account for the resolution of the image in the items when calculating the display size |
AspectRatioCorrection |
Manually change the aspect ratio used to compensate for non-square pixels |
BeginRender |
Temporally disable rendering |
EndRender |
Re-enable rendering |
ImageViewer.Invalidate |
Request that the viewer re-renders the whole or part of the view |
PaintProperties |
Controls the quality used when rendering RasterImage objects |
RedirectRender |
Render the current view to an external context |
ClipImageToContent |
Display only the part of the image inside its content if the item transformation result in a larger boundary |
OwnerDraw |
Turn off or on all automatic rendering of view and items |
Using Image Viewer with Windows.Forms
Image Viewer Bounds and Transform
Image Viewer Rendering