hooovahh Posted December 14, 2006 Report Share Posted December 14, 2006 Hello all, I have a question. I'm looking to display a .ico file which is an icon, on the front panel of a VI, inside a picture control. I seen that there is a Read JPG from File and Read BMP from File which can do exactly what I want but it won't accept .ico files. I've thought about opening an ActiveX object with a web browser to display the icon but I'm not satisified with how it looks. Also this needs to be dynamic, so a copy and paste into the front panel won't cut it. Any comments are appreciated. Thanks. Quote Link to comment
Chris Davis Posted December 15, 2006 Report Share Posted December 15, 2006 I'm looking to display a .ico file which is an icon, on the front panel of a VI, inside a picture control. I seen that there is a Read JPG from File and Read BMP from File which can do exactly what I want but it won't accept .ico files. What about this process: 1. Use ImageMagick to convert ICO file to temp BMP or JPG 2. Read using LV built in tools. Its a two step process, but it just might work. ImageMagick formats LV ImageMagick CR sample I don't know if the Code Repository will help any, but it might. If you come up with a working solution, share it with us. Maybe even make a Code Repository submission... Quote Link to comment
martin@aerodynamics Posted December 15, 2006 Report Share Posted December 15, 2006 Hello all, I have a question. I'm looking to display a .ico file which is an icon, on the front panel of a VI, inside a picture control. You can do it also with irvanview Here is a link from the "Dark side" including an example Open any image with Irfanview Quote Link to comment
hooovahh Posted December 15, 2006 Author Report Share Posted December 15, 2006 What about this process: 1. Use ImageMagick to convert ICO file to temp BMP or JPG 2. Read using LV built in tools. Its a two step process, but it just might work. ImageMagick formats LV ImageMagick CR sample I don't know if the Code Repository will help any, but it might. If you come up with a working solution, share it with us. Maybe even make a Code Repository submission... Yeah your method worked fine, I downloaded ImageMagick and used it's command line utility to convert it to a .bmp file then I was able to display it. I used this method because then I can still manipulate the picture control if I need to. Quote Link to comment
crelf Posted December 15, 2006 Report Share Posted December 15, 2006 Yeah your method worked fine, I downloaded ImageMagick and used it's command line utility to convert it to a .bmp file then I was able to display it... Care to share a VI to demostrate what you came up with? Quote Link to comment
Rolf Kalbermatter Posted January 11, 2007 Report Share Posted January 11, 2007 Hello all, I have a question. I'm looking to display a .ico file which is an icon, on the front panel of a VI, inside a picture control.I seen that there is a Read JPG from File and Read BMP from File which can do exactly what I want but it won't accept .ico files. I've thought about opening an ActiveX object with a web browser to display the icon but I'm not satisified with how it looks. Also this needs to be dynamic, so a copy and paste into the front panel won't cut it. Any comments are appreciated. Thanks. vi.lib\platform\icon.llb\Read Icons from ICO File.vi will read in an icon file into a cluster and also into a Picture control. It's actually what is used in the old Application Builder to support custom icons. Note that there are limitations as to the bitdepths supported here but the Picture control functions should be able to deal at least with 1, 4, and 8 bit icons. I would expect this library to not work well with the XP style icons inside some icon file but the rest should be fine. Rolf Kalbermatter 1 Quote Link to comment
eberaud Posted January 26, 2017 Report Share Posted January 26, 2017 Reviving an old thread! It's 10 years later, and the VI rolfk mentioned looks like it hasn't got any love. Any chance you know of an updated equivalent that would support 32 bit depth? Quote Link to comment
hooovahh Posted January 27, 2017 Author Report Share Posted January 27, 2017 Just tested my stand by method of using .Net and it seems to open and work just fine. Here is the code I posted over on the NI forums a while ago. It opens an image using .Net and then scales it to fit to the pane without any extra work. It supports all the different image file types, alpha layers, and can be exported back into LabVIEW Image Data. Quote Link to comment
eberaud Posted January 27, 2017 Report Share Posted January 27, 2017 Looks neat, thanks hooovahh. Now my problem is that it always uses the first (higher resolution) image of my .ico file. I need some code to choose which image to use. The vi.lib\Platform\icon.llb\Read Icons from ICO File.vi VI returns an array of clusters named icon data but those clusters are different from the imagedata.ctl typedef used by your VIs.. Quote Link to comment
hooovahh Posted January 30, 2017 Author Report Share Posted January 30, 2017 Uggh, this does not look easy. Here is some VB code that looks to attempt to pull individual icons out of an icon file, and then load them into a picture box. https://www.codeproject.com/articles/6171/access-multiple-icons-in-a-single-icon-file Sorry I don't have any good suggestions. Quote Link to comment
eberaud Posted January 31, 2017 Report Share Posted January 31, 2017 Yeah no time to dig through VB code for now. Thanks, I appreciate the help Quote Link to comment
hooovahh Posted January 31, 2017 Author Report Share Posted January 31, 2017 1 hour ago, Manudelavega said: Yeah no time to dig through VB code for now. Well that's okay I felt like doing some improvements on the image manipulation code. Attached is an improved version that supports ico and tif files and allows to select an image from within the file. For ico files it basically grabs the one image you select (with Image Index) and make an array of bytes that is a ico file with only that image in it, and then displays it in the picture box. For Tif files there is a .Net method for selecting the image which for some reason doesn't work on ico files. Edit: Updated to work with Tifs as well. Image Manipulation With Ico and Tif.zip 1 Quote Link to comment
hooovahh Posted February 7, 2017 Author Report Share Posted February 7, 2017 Pretty minor but I found a bug where I wasn't releasing the image before loading the next. The result is memory will always increase, until the VI stops running and the garbage collector runs. Not a big issue for small files but someone loaded a 1GB TIFF file and had issues. Updated version can be found on the dark side. Quote Link to comment
eberaud Posted February 8, 2017 Report Share Posted February 8, 2017 I like to understand the code I'm using instead of just blindly using it "since it works" I'm looking at your Read Ico File.vi. I found a Wikipedia page that describes the format of an .ico file so I understand perfectly what you're doing when you index the bytes coming from it. However I can't find anything that describes the content of a .NET Image Byte Array, so I don't understand what you're doing when you create that array. Can you point me to a web page that would explain this format? Cheers! Quote Link to comment
hooovahh Posted February 8, 2017 Author Report Share Posted February 8, 2017 I don't fully know what you are asking. Are you asking how I get the Image Data using the Get Image Data From PictureBox.vi? All that is doing is making a memory stream (a place in memory that has an array of bytes that can be used for various memory stuff). Then save the image into a PNG file, but instead of saving it into a file on disk, it saves it to the memory stream. Now the memory stream contains the same bytes that the file would have, if I saved the image as a PNG file on disk. Then using this array of bytes that is a PNG file, we use a vi.lib function to go from the data to LabVIEW Image Data. This will basically turn any image that the .Net functions can open, into a PNG, then into the LabVIEW Image Data. This is useful, but could be inefficient. Improvements could look at the file type that the incoming image is, and save the stream to the same file type, then open it with the appropriate function. Or possibly turning that directly into the 2D Picture data type. But honestly this is generally used for small to medium sized images and I haven't seen any memory issues. Quote Link to comment
eberaud Posted February 9, 2017 Report Share Posted February 9, 2017 My question is about the piece of code in this screenshot of Read Ico File.vi. You seem to reassemble an .ico file again. Is that what you're doing? Quote Link to comment
hooovahh Posted February 9, 2017 Author Report Share Posted February 9, 2017 Oh I thought that was pretty clear. So we take out the one image you selected, but then need to put in the header information. In that header information is stuff like how many images are there in the file, and at what file offsets are the images. The first image should always be at offset 22. The second image (if there is one) is after the first image, so its offset is going to vary depending on the size of the first image. In the VB code I linked to earlier this is the variable newCount and newOffset which the comment states is 6 bytes + 16 bytes 6 bytes for the ICONDIR, and 16 bytes for the first image ICONDIRENTRY. I mostly just reproduced the VB code in LabVIEW once I realized what it was doing. I also used Wikipedia. Also I find it kinda funny how I started this thread about 11 years ago and now have an answer that I find satisfying, even though it adds a .Net dependency. Quote Link to comment
eberaud Posted February 9, 2017 Report Share Posted February 9, 2017 I see, so long story short, you don't really extract the PNG and feed it to .NET, you rather manipulate the ICO and then feed it to .NET still as an ICO. Correct? Quote Link to comment
hooovahh Posted February 9, 2017 Author Report Share Posted February 9, 2017 Yup, the .Net part accepts many different image types. ICO is one of them so I pass in the stream that is an ICO file that is then displayed in the PictureBox, or saved back as a new PNG stream. Same with all the other file types, .Net opens a JPG and displays it, then saves it as a PNG stream, then LabVIEW interprets it as LabVIEW data. 2 Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.