One way to convert the .NET PictureBox image to an IMAQ Image is to use a memory stream.
- Use a Property Node to get a reference to the current Image in the .NET PictureBox.
- Add an Invoke Node and navigate to Select Method » Save(Stream stream, ImageFormat format)
- To create the memory stream, first add a Constructor Node. Then right-click and press Select Constructor... . Select the mscorlib(4.0.0.0) assembly from the drop-down list. Navigate to System.IO.MemoryStream under Objects and select the MemoryStream() constructor. Press OK.
- Wire the refnum of the constructed memory stream to the stream input of the Save method invoke node you created in step 2.
- Next select the image format. Add a Property Node, right-click and navigate to Select Class... » .NET » System.Drawing.Imaging.ImageFormat. Then, right-click again and press Select Property to choose png as the image format.
- To access the memory buffer, add a new Invoke Node, wire a reference to the memory stream, and select method GetBuffer(). This returns a byte array representing the image in png-format.
- Convert the byte array to a string and use PNG Data to LV Image.vi to convert the data to a cluster of image data.
- The Unflatten Pixmap.vi can then convert the image data to a 2D array of pixel values, i.e. a pixmap.
- Finally, the pixmap can be converted to an IMAQ Image using the IMAQ ArrayToColorImage.vi.
Additional Information
For more details about the .NET classes, their properties and methods, consult the external link:
.NET API Browser.
For supported image format verification, kindly check
Reading and Writing Image File .