Tutorial: Display Images in an Image Viewer

The LEADTOOLS ImageViewer is a cross-platform viewer that provides image display controls for desktop, web, tablet, and phone applications. Not only can this viewer display more than 150 different file formats, it also has a numerous amount of interactive modes that can be incorporated to your company’s workflow. These modes provide an efficient and friendly user experience.

Once you get the ImageViewer up and running, there is so much more that you can do besides viewing images. You can add options to annotate and mark up images, OCR images, and improve the image quality of document images with the LEADTOOLS Document Cleanup Image processing functions. The LEADTOOLS ImageViewer library can be added to just about any workspace and help you out within minutes, so try it out!

The below code shows the basics of loading an image in the image viewer using both Winforms and WPF. If you want a complete step-by-step tutorial, check out our tutorials:


private _viewer imageViewer; 

private void Form1_Load(object sender, EventArgs e) 
   _viewer = new ImageViewer(); 
   _viewer.Dock = DockStyle.Fill; 
   _viewer.BackColor = Color.DarkGray; 

private void openToolStripMenuItem_Click(object sender, EventArgs e) 
    using (RasterCodecs codecs = new RasterCodecs()) 
            OpenFileDialog dlg = new OpenFileDialog(); 
            dlg.InitialDirectory = @"C:\Users\Public\Documents\LEADTOOLS Images"; 
            if (dlg.ShowDialog(this) == DialogResult.OK) 
               _viewer.Image = codecs.Load(dlg.FileName); 


private ImageViewer imageViewer; 
private RasterCodecs codecs; 

// Initialize Image Viewer 
private void InitViewer() 
    // Create new instance of ImageViewer 
    imageViewer = new ImageViewer 
        Background = SystemColors.AppWorkspaceBrush, 
        UseDpi = true, 
        ViewPadding = new ControlPadding(), 
        ViewHorizontalAlignment = ControlAlignment.Center, 
        ViewVerticalAlignment = ControlAlignment.Center, 
    // Add viewer to the imageViewerGrid 
    // Add pan and zoom functionality 
    var panZoom = new ImageViewerPanZoomInteractiveMode(); 
    // Instantiate RasterCodecs 
    codecs = new RasterCodecs(); 

private void _fileOpen_Click(object sender, RoutedEventArgs e) 
    OpenFileDialog dlg = new OpenFileDialog(); 
        dlg.InitialDirectory = @"C:\Users\Public\Documents\LEADTOOLS Images"; 
        if (dlg.ShowDialog() == true) 
            imageViewer.Image = codecs.Load(dlg.FileName); 

Try it out!

To test this for yourself, make sure to get the latest LEADTOOLS SDK evaluation for free from our site, if you have not already. This trial is good for 60 days and comes with unlimited chat and email support.


Need help getting this sample up and going? Contact our support team for free technical support! For pricing or licensing questions, you can contact our sales team (sales@leadtools.com) or call us at 704-332-5532.

Stay tuned because, as promised in our previous post, “Convert Images to Searchable PDF with OCR “, we’ll be featuring a lot more tutorials that programmers can use to develop applications that directly impact data capture, recognition, exchange, and other pressing business needs.


Developer Support Manager

This entry was posted in File Formats and tagged , , . Bookmark the permalink.

2 Responses to Tutorial: Display Images in an Image Viewer

  1. Keith Stacy says:

    I need to learn whether your image viewer can support annotations; specifically, the ability to draw a rectangular bounding box enclosing part of the displayed image, and exposing the coordinate values from that bounding box for reading/writing to a backing store.

    • Hi, Keith.

      Thank you for your interest in LEAD and LEADTOOLS!
      The image viewer can do that. I will ask support to reach out to you to help get you started.


Leave a Reply

Your email address will not be published. Required fields are marked *