LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Display EMF Image Front Panel

I'm looking to display a grid of EMF images that are saved on disk, to the front panel so the user can select one.  I have a couple of options but none are perfect so I was wondering if someone could help give me some ideas.

 

Option A: Use the .Net Picture Box to load EMF images.  Because I want to display a grid of them that the user can vertically scroll through, that would mean lots of picture boxes each loading one file.  I could have a separate vertical scrollbar that scrolls the pane of the front panel.  Since many images could be displayed at once I was thinking of just loading the number of rows displayed plus N extra, then close and re-open more as the user scrolls.  I could do this with subpanels, each with the .Net picturebox but managing is still a pain.  I am also unsure what performance is like when you need to load a grid of many images.

 

Option B: Export those EMFs into PNG images, then load those into the grid as needed.  This would mean the images won't be able to change in size, except maybe a zoom level on the picture indicator.  This would also make things larger since for every EMF image I need to export to a PNG.  I would likely also want to only load images that are needed so there would be a single 2D picture control that has the origin set by a separate scrollbar.  Then images could be updated as you scroll.  The down side of this is my package now needs to be larger, since for every EMF file I need a PNG, just for display purposes, and images are going to be at a set size.  That last one isn't that big of a deal I'll just pick a size that is most useful and go with it.

 

Option C: Is there a way to get the image data of a EMF file within LabVIEW directly?  If so I can load this grid of EMF files just like the PNG Option B route, but I won't have to export them to many PNG files, and I can resize as needed.

 

Not sure what performance is going to be like but my benchmark is pretty slow at the moment.  I'm really just hoping for some low level LoadImage function LabVIEW might have that I'm unaware, since EMF images are supported on things like custom controls.

0 Kudos
Message 1 of 12
(1,965 Views)

Not sure if I understand correctly, you should be able to drag & drop an emf file onto front panel.

 

 

George Zou
0 Kudos
Message 2 of 12
(1,956 Views)

@zou wrote:

Not sure if I understand correctly, you should be able to drag & drop an emf file onto front panel.

 

 


You can.  I want to dynamically load a list from disk.  Imagine I have 8000 or so EMF files, and then the user will give some kind of search criteria and I will then display a grid of the images that match the criteria.  Then they might adjust the search and I want to give a new list of images.

0 Kudos
Message 3 of 12
(1,944 Views)

"EMF, acronym of “Enhanced MetaFile”, is an image format most used in Windows OS."

Not to be confused with "Electric Magnetic Fields"

I was having mental contortions trying to picture that. 🤕

---------------------------------------------
Certified LabVIEW Developer (CLD)
0 Kudos
Message 4 of 12
(1,935 Views)

Where can you even get EMFs these days? Googling is proving... unfruitful.

 

I've got libraries that could help out with the scroll bits but outside of some old scada graphics libraries I used years ago I haven't seen EMFs in ages to test some ideas with.

0 Kudos
Message 5 of 12
(1,891 Views)

Don't think this would work, but

 

you could copy the file into the Windows Clipboard using something like this,

then paste the the copied contents into a 2d Picture control. If it does work it may be slow.

0 Kudos
Message 6 of 12
(1,886 Views)

@Hooovahh wrote:

 

Option C: Is there a way to get the image data of a EMF file within LabVIEW directly?  If so I can load this grid of EMF files just like the PNG Option B route, but I won't have to export them to many PNG files, and I can resize as needed.


Presumably you could go through .NET by loading the image and then saving to a PNG stream, although I haven't tried that.

 

Another thing which might work and I haven't tried is to use a single PictureBox to display all of the images (i.e. load the images using the Image class and use a Graphics object in the PictureBox to call DrawImage to specific coordinates). I don't know if this would work and what the performance would be, and it would probably be more of a pain to manage, especially if you do want separate scrollbars for each image in the grid, but it's possible that this is the best option.


___________________
Try to take over the world!
0 Kudos
Message 7 of 12
(1,792 Views)

@DerrickB wrote:

Where can you even get EMFs these days? Googling is proving... unfruitful.


From SVGs obviously.  I'm updating a tool of mine for control creation and I'm looking at ways to improve it.  Previously I used libraries of SVGs that are vector images and scale well.  But these first needed to be converted to EMFs so that they can be put into the boolean controls.  Here is a demo of the current code, which also has the PNG images for the UI.

 

https://www.youtube.com/watch?v=zBp7xIZCi-Y

 

If I can just have a viewer for the EMFs then I don't need to bother with the PNGs.  The single picturebox method might work.  Performance is just a concern.  Again the extreme example is having a couple thousand EMF images, that need to be converted to PNG streams, then loaded and displayed.  I could prioritize the scrolled position of the user, then load the rest in the background giving the illusion of responsiveness.  Previously it worked well enough with Windows Explorer doing the heavy lifting, but again that relied on having a duplicate set of PNG images.

0 Kudos
Message 8 of 12
(1,740 Views)

Turns out the .NET method isn't slow at all.  My first attempt was to take an already made CTL control file, then replace the decal button with the EMF file, perform a resize on the control in VI Server (if needed) then save the control's image to a temp location as PNGs to load later.  This didn't seem too bad, and with some parallel for loops I could load 40 EMF images into controls in about 2 seconds.  On consecutive loads I can just go load the PNG saved earlier which only took 20ms or so to load those 40 images.

 

But .Net worked out much better.  Using some modified code from here, I can tell it to load the EMF file from disk, resize it, then save it to a PNG stream, which can be displayed, and saved to disk for later.  This operation only takes 120ms for those same 40 images, or down to 80ms with a few parallel loops. 

 

I still need work on pipelining the whole thing, and prioritizing where the scroll bar happens to be, but I don't think it will be that bad.  The last time I tried this loading all the PNGs from disk was painfully slow.  Maybe these set of images load faster because they are more simple?  I'll have to do more testing but things look pretty good.  I also tried loading them all into a single Picture Control so that scrolling could be smooth.  That's a big no.  Loading 8000 PNGs that are 56 pixels in size, all shifted into 10 columns and 7000 rows led to a very choppy scrolling feel.  An array of 2D pictures works much better.  Maybe I could see using an array for a large number of results, and a 2D picture for a smaller set?  But at this point I'm just going with an array.  If I finish this project I'll try to remember to post an update.

0 Kudos
Message 9 of 12
(1,704 Views)

@Hooovahh wrote:

Option C: Is there a way to get the image data of a EMF file within LabVIEW directly?  If so I can load this grid of EMF files just like the PNG Option B route, but I won't have to export them to many PNG files, and I can resize as needed.


I do have a library (somewhere) to create EMF files. (Not sure if it reads EMFs as well, IIRC to some extend.)

 

The spec is open, but EMFs can do more then a picture control can. So a subset of EMF objects can be parsed and displayed in a picture control. For instance: paths (gradients) wouldn't be easy (you'd have to use DIY raster rendering).

 

EMF should be fast (in .NET), as it (by design) closely maps to CGI\CGI+, which is M$'s workhorse for graphics.

0 Kudos
Message 10 of 12
(1,670 Views)