Introduction
TIFF is a widely used file format employed in numerous image manipulation applications including (but not limited to) scanning, faxing, and optical character recognition. It is a mature format for storing raster images, whose last major update was in 1992.
This article provides a ready-to-use TIFF viewer control based on .NET's already existing capabilities, thus its brevity. The control has limitations and is obviously no match for commercial TIFF viewers feature-wise or performance-wise, but it should be sufficient for application with limited TIFF viewing needs.
Background
I occasionally need for prototype applications containing TIFF viewers. Although .NET's GDI+ already contains the functionality to decode and manipulate TIFF files, expensive commercial TIFF viewers are used for displaying TIFF files. The ones who have experience with them would agree that it is a tedious task properly setting them up (packing up the necessary set of DLLs, including the licenses, taking care of 32bit/64bit compatibilities, etc.).
With this in mind, I thought a bare-bones TIFF viewer control depending on .NET alone would already be available somewhere. But the ones I could find did not meet my needs. One I could displayed multipage TIFFs but was missing thumbnails support, another one did have thumbnails support, but it was for ASP.NET. So I decided to come up with my own control.
Control Basics
The control loosely follows the Model-View-Presenter (MVP) Pattern, so I will breakdown the control's classes according to their pattern roles:
Model
TiffImage class constitutes the model part. It contains the actual TIFF image data, which is stored in a System.Drawing.Bitmap object. It also contains a cached working copy of the image having the currently displayed page with the current zoom ratio.
Viewers
Three classes are used as viewers:
PageControlA PictureBox is used to display the current page of the TIFF file.
The only thing worth mentioning is the panning support. PictureBox's MouseDown(), MouseMove(), MoveUp() methods are implemented to support image panning.
ThumbnailsControl
With a few minor modifications, standart ListView has everything we need to be used as a thumbnail viewer.
A TIFF file may contain hundreds of pages, so we would not want all of our thumbnails to be loaded at startup. Here, the listview's virtual mode comes to our rescue. In virtual mode, the ListView requests only the thumbnails that are about to be displayed.
I use the ListView in LargeImage mode. I bind to listview to an empty ImageCollection and then I populate it with the pages' thumbnails as needed. The icons representing the thumbnails are all set to 100x100, TiffImage.GetThumbnail() shifts the images so that they are centered in this 100x100 viewport.
ToolbarControl
The ToolbarControl has a ToolStrip control which contains buttons to zoom in/zoom out the image, select the page of TIFF file to display.
Presenter
TiffViewer is the presenter and the control itself. It controls the interaction between the model and views described above.
Using the control
A single DLL, TiffViewerLib.dll is required for the control. Right click on your Visual Studio Toolbox, select 'Choose Items...', select 'Browse...', select 'TiffViewerLib.dll'. Drag the TiffViewer control from the toolbox to your form. Set the Path property of the control to the TIFF file you would like to view.