Example Code

Resize ImageViewer based on Image Size in Vision .NET.

Code and Documents

Attachment

Overview

In a windows forms application it may be useful to automatically resize the image viewer area to that of the image you are attaching.  This means that you do not have to statically layout your image viewer control in development and can modify the size of the control at run time.  The image viewer will by default allow a user to pan through the image, but this may not be as useful as the ability to view the entire image.

Description

This code allows a user to read in an image using the open file dialog browser.  The user can select any color image available and the program will automatically resize the ImageViewer to display the entire image in the form.

Steps to Implement or Execute Code

  1. Unzip the file attached
  2. Open the 'AutoSizeImageViewerExample.sln' file in Visual Studio
  3. Run the code
  4. Select the 'Read Image' button and browse to any color image saved on the computer.
  5. Observe the ImageViewer change in size to reflect the size of the image selected

Requirements

Software

Visual Studio 2012

NI Vision

NI Vision Acquisition Software

Hardware

N/A

Additional Images or Video

The code used to modify the image viewer size is the ImageViewer.Size property, which is set to the same size that we can get from the Image we read in.


ImageViewerResize.PNG



Cole R.
National Instruments
Software Engineer

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors