LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How would I convert a .NET picturebox image to a LabVIEW Picture Control or IMAQ image?

How would I take an image from a .NET picturebox (System.Windows.Forms.PictureBox) and put it into a 2D Picture control or IMAQ image?

 

Can it be done without saving the image (System.Drawing.Image: Save) and re-loading it with Read PNG File.vi or IMAQ ReadFile.vi?

0 Kudos
Message 1 of 6
(4,099 Views)

For context:

 

I'm creating a front-end for Mathematica in LabVIEW, using .NET and Wolfram's .NET/Link as a middleman between LV and Mathematica. One of the things I'm doing returns a picture in Mathematica, which can output to a .NET picturebox. I'd like to continue to manipulate the image using standard LV Picture Control VIs.

0 Kudos
Message 2 of 6
(4,093 Views)

I originally bit the bullet and just used the Image Save method and reload using the Read PNG VI.  I have had limited success at best using the newer PNG Data to LVImage VI, it has trouble with many PNG files and is much less robust than the file version.   It is also a bit of a pain to save to a memory stream in .NET, but not too bad once you find all the necessary constructors.  

 

You can also use the BMP format and rip out the necessary parts from the Read from BMP file (completely open, bit of an adventure in there).  This also lets you avoid the file write/read step.

 

What I do now in my Mathematica Front End is use my homemade PNG subVIs to read the PNG string from .NET and display it in a picture box.  Is it worth all of the extra code to avoid a single file write/read, I think not at this point.

Message 3 of 6
(4,084 Views)

You can get the pixel map by taking pixel by pixel data using GetPixel method, and combining it with a for loop of picture width*height and multiplying each pixel by x and y output of this method.

I've done something similar to this long back, and you could get lots of C# code examples where the program reads the bmp file and outputs a 2D array of pixel map.

Once this part is done, you could draw the image directly using picture functions.

If you are doing this for speed improvement of your program, this would indeed help since this would happen on the fly in system memory.

 

-FraggerFox!
Certified LabVIEW Architect, Certified TestStand Developer
"What you think today is what you live tomorrow"
Message 4 of 6
(4,082 Views)

Hello, dthor!

 

It looks like Darin.k and Fragger Fox have given you some good suggestions. Have you been able to try these out? Let us know if you're still having issues.

Will Hilzinger | Switch Product Support Engineer | National Instruments
0 Kudos
Message 5 of 6
(4,067 Views)

@Fragger Fox:

 

I was able to get the GetPixel method working, but it was extremely slow for some reason. A 275x275 px image took a good minute and a half. Granted, this was just first-order coding; I'm sure I could speed it up some.

 

@Darin.K

 

I haven't had any issues with saving/loading a PNG, but I'm not limited to a specific format so I'll be sure to keep your suggestion in mind if I come into issues.

 

 

For now I'm just saving to a temporary file and loading from the file. It's not ideal, but I'm also just doing proof-of-concept work so I don't really care all that much.

0 Kudos
Message 6 of 6
(4,063 Views)