Using .NET to display images in LabVIEW

Download Demo Code

Here’s a quick tip that I’ve found useful in the past when displaying images on the front panel at runtime.  The built in 2D Picture control is quick and easy to use for this purpose, but if you want to do anything more complex than simply displaying an image, you’ll likely find that a better solution exists.  The primary issue I’ve run into involves displaying images that are a different resolution from the 2D Picture control itself.  The 2D Picture control makes no attempts to handle this situation, it just simply displays the image pixel for pixel.  This means if the image is too big, it will get cut off, and if it is too small, it will leave whitespace.

Capture

Luckily, LabVIEW gives us the ability to use .NET controls, and the .NET PictureBox control solves this problem nicely.  As shown in the demo code, loading an image into a .NET PictureBox is as simple as calling the “Load(url)” method and passing in the image file path as a string.  Then, to set the image scaling, just set the “SizeMode” property of the PictureBox control.  There are several SizeMode options, but the one I use most often is “Zoom”.  Feel free to play around with the Demo Code to see what the other SizeMode options do.

Capture2

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s