Click here to Skip to main content
15,885,278 members
Articles / Desktop Programming / Windows Forms

Poor Man's TIFF Viewer

Rate me:
Please Sign up or sign in to vote.
4.50/5 (13 votes)
25 Oct 2015CPOL3 min read 21.3K   2.5K   15   6
A Single-DLL, multi-page TIFF .NET viewer control with panning and thumbnails support

Introduction

Image 1

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:

The following project displays multipage TIFFs but is missing thumbnails support:

http://www.codeproject.com/Articles/31247/Multipage-TIF-Viewer

The following project does have thumbnails support, but it is for ASP.NET:

http://www.codeproject.com/Articles/64146/ASP-NET-Multipage-TIFF-Viewer-with-Thumbnails

So I decided to come up with my own control.

Control Basics

Image 2

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

Image 3

Three classes are used as viewers:

PageControl

A PictureBox is used to displayed 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 describeed 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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Turkey Turkey
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionGetting selected page number Pin
HassanMehdy11-Oct-18 23:05
HassanMehdy11-Oct-18 23:05 
QuestionPoor mans Tiff Viewer Pin
Faisal4328-Apr-18 4:47
Faisal4328-Apr-18 4:47 
SuggestionReset Page Index Dictionary on Open Pin
papaboar29-Feb-16 4:58
papaboar29-Feb-16 4:58 
QuestionReset TiffViewer control Pin
Richard V Williams25-Nov-15 0:47
Richard V Williams25-Nov-15 0:47 
AnswerRe: Reset TiffViewer control Pin
Abdul Hannan Fiaz9-Nov-18 5:10
professionalAbdul Hannan Fiaz9-Nov-18 5:10 
GeneralMy vote of 4 Pin
newton.saber26-Oct-15 4:30
newton.saber26-Oct-15 4:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.