Example Code

Using the .NET PictureBox Control to Automatically Scale Images using LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview
As shown here, resizing images can be done with the native LabVIEW 2D Picture control and built in VIs, but it requires some cumbersome mathematics.  This document explains how to use the .NET PictureBox control to easily scale images in a variety of ways. 


Description
The .NET PictureBox control is a powerful control that can be used from within LabVIEW to display images.  This control provides some built in functionality which can be tedious using native LabVIEW VIs.  One such feature which is extremely simple to implement using the .NET PictureBox control is image scaling.

As shown in the demo code, to load an image into a .NET PictureBox simply call the "Load(url)" method and pass in the image file path as a string.  To set the image scaling, set the "SizeMode" property of the PictureBox control.  SizeMode options include: Normal, StretchImage, AutoSize, CenterImage, and Zoom.  Normal simply displays the image data in the control in a 1:1 pixel mapping, possibly leaving whitespace or cropping the image (just like the native LabVIEW 2D Picture control).  StretchImage fits the image data to the PictureBox by scaling both the height and the width (possibly distorting the image in the process).  AutoSize will scale the PictureBox control to match the image data size.  CenterImage will retain the image scaling just like Normal, but will center the image data in the PictureBox control.  Zoom will scale the image data to fit within the PictureBox control, but will retain the image data proportions (in other words, it will not distort the image).

 

Requirements

Software:

  1. LabVIEW 2014(or compatible)


Steps to Implement or Execute Code

1.Unzip the attached folder to your computer

2.Open the VI "dotNET PictureBox Demo 2014 NIVerified"

3.Run the program

 

Additional Information or References
VI Block Diagram

 1.png

 **This document has been updated to meet the current required format for the NI Code Exchange.**

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

Comments
cnathan
Member
Member
on

Perfect.  Just what I needed.