How Can I Programmatically Insert An Image Into A Picture Control and Resize The Control?

Problem:I want to insert an image into a picture control in LabVIEW and match the size of the image and control programmatically. How can this be done without manually resizing the picture on the front panel?

Solution:Copying and pasting a picture from the clipboard or dragging a picture into the front panel simply makes the picture a front panel object decoration. The process to correctly insert an image into a picture control and programmatically resize it is:

Insert a 2D Picture control on the front panel from Modern»Graph»Control in the Controls Palette

Go to the block diagram and place the appropriate read picture file VI from Programming»Graphics andSounds»Graphics Formats in the Functions Palette. Depending on the type of picture, choose the appropriate read picture file VI:

File Type

Read Picture File VI

.bmp

Read BMP File.vi

.jpeg

Read JPEG File.vi

.png

Read PNG File.vi

On that read picture file VI, right-click on the path to picture file input (ex: path to JPEG file) and select Create»Control

Place a Draw Flattened Pixmap.vi and a Empty Picture.vi on the block diagram from Programming»Graphics and Sounds»Picture Functions in the Functions Palette

Place an Unbundle By Name function on the block diagram from Cluster & Variant in the Functions Palette and wire it to the output of the read picture file VI

Expand the Unbundle By Name to have two outputs and choose the Rectangle»right for the top output and Rectangle»bottom for the bottom output.

Place a Bundle VI next to the Unbundle By Name

Right-click on the Picture Control indicator and select Create»Property Node»Draw Area Size to place the area property node onto the block diagram

Right click on the property node and select Change to Write

Wire the functions as shown in the image below

An example program called Insert Image.vi is attached that performs this operation.