Support for loading large amount of items in an ImageViewer.
public abstract class ImageViewerVirtualizer
public ref class ImageViewerVirtualizer abstract
The ImageViewerVirtualizer provide support for handling large amount of image data in an ImageViewer by loading and unloading item data on demand with full control for rendering place-holders and controlling the number of items to cache in memory.
For detailed information, refer to Image Viewer Virtualizer.
using Leadtools;
using Leadtools.Controls;
using Leadtools.Codecs;
using Leadtools.Drawing;
public ImageViewerForm _form = new ImageViewerForm();
public ImageViewer _imageViewer;
public void ImageViewerVirtualizerExample()
{
// Get the input file name
string _imageFileName = imageFileName;
// Get the ImageViewer control from the form
_imageViewer = _form.ImageViewer;
// Set to vertical view layout
_imageViewer.ViewLayout = new ImageViewerVerticalViewLayout();
// Add pan zoom interactive mode
_imageViewer.InteractiveModes.Add(new ImageViewerPanZoomInteractiveMode());
// Add empty items, each one with the correct size but with no image data
// The virtualizer will take care of loading the pages and rendering them
using (RasterCodecs codecs = new RasterCodecs())
{
int pageCount;
LeadSize pageSize;
LeadSizeD pageResolution;
using (CodecsImageInfo info = codecs.GetInformation(_imageFileName, true))
{
pageCount = info.TotalPages;
pageSize = LeadSize.Create(info.Width, info.Height);
pageResolution = LeadSizeD.Create(info.XResolution, info.YResolution);
}
_imageViewer.BeginUpdate();
for (int page = 1; page <= pageCount; page++)
{
ImageViewerItem item = new ImageViewerItem();
item.ImageSize = pageSize;
item.Resolution = pageResolution;
_imageViewer.Items.Add(item);
}
_imageViewer.EndUpdate();
// Set the virtualizer to start loading the data into the empty items
_imageViewer.Virtualizer = new MyVirtualizer(_imageFileName);
// Hook to the VirtualizeItemReady to log each item as its image data is loaded
_imageViewer.VirtualizeItemReady += (Object sender, ImageViewerVirtualizerEventArgs e) =>
{
System.Diagnostics.Debug.WriteLine("Image data for page " + (e.Item.RowIndex + 1) + " is ready");
};
}
}
// Custom Virtualizer
public class MyVirtualizer : ImageViewerVirtualizer
{
private string _imageFileName;
public MyVirtualizer(string imageFileName) : base()
{
_imageFileName = imageFileName;
// Load 4 items at a time
this.MaximumItems = 4;
}
protected override object LoadItem(ImageViewerItem item)
{
// Load a page, the page number is the item index, but it
// could be anything in the application, for example
// using ImageViewerItem.Tag to store the necessary data to identity this item
int pageNumber = this.ImageViewer.Items.IndexOf(item);
using (RasterCodecs codecs = new RasterCodecs())
{
return codecs.Load(_imageFileName, pageNumber);
}
}
protected override void SaveItem(ImageViewerItem item, object data)
{
// Nothing to do in this application, just log it.
// If save is required, then this is the place to do it
int pageNumber = this.ImageViewer.Items.IndexOf(item);
System.Diagnostics.Debug.WriteLine("SaveItem for page " + pageNumber + " is called");
}
protected override void DeleteItem(ImageViewerItem item, object data)
{
// Dispose the image
RasterImage image = data as RasterImage;
if (image != null)
image.Dispose();
}
protected override void RenderItemPlaceholder(ImageViewerRenderEventArgs e)
{
// Render the placeholder for this page
int pageNumber = this.ImageViewer.Items.IndexOf(e.Item) + 1;
LeadMatrix transform = this.ImageViewer.GetItemImageTransform(e.Item);
Graphics graphics = e.PaintEventArgs.Graphics;
// Render the message at 0,0 in this item transformation
LeadPointD pt = LeadPointD.Create(0, 0);
pt = transform.Transform(pt);
string message = string.Format("Loading page {0}...", pageNumber);
graphics.DrawString(message, this.ImageViewer.Font, Brushes.Black, (float)pt.X, (float)pt.Y);
}
}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document