Return to site

LabVIEW Picture Autozoom

· LabVIEW,Picture,autozoom

I have a picture indicator in my VI and I might want to show pictures of all sizes. I wanted to figure out a way to change the size of the picture so that it would maximize in the window. After some experimenting, I came up with this.

LabVIEW picture autozoom zoom

To explain a little further. First, get the PNG file data and get its dimensions. Then, get the dimensions for the picture indicator. Divide the the picture width by the PNG width and divide the picture height by the PNG height. Pick the lower number and set that as the Zoom factor. Also, set the picture indicator to show the PNG data.

A few notes:

  • Numbers are converted to Single because Zoom Factor is a single.  (Random note about me is that I prefer to not have coercion dots in my LabVIEW code.)
  • This code can be converted for JPG or BMP files as well.  Just change the Read file VI to the appropriate one.  
  • If your zoom factor is very big or very small, your picture may not look very good.  You may want to have code that allows your user to bypass this autozoom code.