Example Code

Convert JPEG String to LabVIEW Image

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview
This VI converts JPEG string to LabVIEW image.


Description
You can convert JPEG string to LabVIEW image. This is particularly useful if you wish to view the image of JPEG string on VI.


Requirements

  • LabVIEW Base Development System 2012 (or compatible)


Steps to Implement or Execute Code

  1. Unzip the attached folder to your computer
  2. Open the VI "DOTNET – JPEG String to LabVIEW Image 2012 NI Verified.vi"
  3. Enter JPEG string
  4. Run the program

 

Additional Information or References
In case you need JPEG string to check the functionality of this example, you can find example code on the same web page that loads user-specified JPEG file and converts LabVIEW image to JPEG string.

 

 

 **This document has been updated to meet the current required format for the NI Code Exchange.**

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
Alex.T
Active Participant
Active Participant
on

Would you be able to downconvert these VIs to 2010? It'd be cool to see how the conversion is implemented.


Alex Thomas, University of Manchester School of EEE LabVIEW Ambassador (CLAD)

GriffinRU
Member
Member
on

No problem, attached in zip

-Artur

Lexilighty
Member
Member
on

If I am writing to Memory Stream in C#, can I access the data I am writing to memory stream in Labview?

I am writing something of this sort from a tracked human face to memrory stream but I am not sure how to read the process in labview:

                        this.facePoints3D = frame.Get3DShape();

                    

                        using (MemoryStream stream = new MemoryStream())

                        {

                            var sw = new StreamWriter(stream);

                           

                            foreach (var vector in facePoints3D)

                            {

                               float zvect = vector.Z;

                                //sw.WriteLine(max);

                                sw.WriteLine(zvect);

                                 // The string is currently stored in the

                                 // StreamWriters buffer. Flushing the stream will

                                 // force the string into the MemoryStream.

                                 sw.Flush();

                                 }

                           

                            stream.Position = 0;

                            StreamWriter writemem = new StreamWriter("coordinates.txt", true);

                           

                            using (writemem)

                            {

                                var read = new StreamReader(stream);

                                var myread = read.ReadToEnd();

                                writemem.WriteLine(myread);

                               

                               

                            }

                          

                        }

Thanks man!

GriffinRU
Member
Member
on

Hi,

You can do that over "AllocHGlobal":

Process A (C#) Marshal -> AllocHGlobal -> Marshal -> Copy -> pointer

Process B (LabVIEW) Marshal -> AllocHGlobal -> Copy -> array

-Artur

Lexilighty
Member
Member
on
Lexilighty
Member
Member
on

Can you give an example of both instances please?

GriffinRU
Member
Member
on

I am sorry, missed your question, do you still need an example or you done?

-Artur

funhistory
Member
Member
on

I was hoping to use your example to decode a JPG string from an old video camera, which is 24-bit.  I noticed that your DOTNET code only works with 32-bit images.  Is there a reason for that?  Could you refer me to a resource where I could learn how to tailor your code for 24-bit JPGs?

dadreamer
Active Participant
Active Participant
on

For anyone interested in this here's a WinAPI method to convert an image stream into a common 32-bit RGB array. Doesn't require saving a stream into a temporary file.