LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Base64 encode/decode function

Hi please I need A small program to convert base64 to PNG image

Regards

0 Kudos
Message 1 of 13
(4,992 Views)

Why did you think that attaching your request to a totally unrelated thread would be a good idea?

 

Basically you have two thing you need to do. Decode a Base64 encoded string and convert the binary result from a PNG image byte stream into a LabVIEW displayable image. Both have been discussed many times on these fora and elsewhere on the internet. Did you search for that? What did you come up with and what have you tried so far?

 

The Base64 decoding is trivial to do. There is a function for that in the HTTP Client VI library. It's not on the palette directly but you can find it in vi.lib\httpClient. Have you tried that? It's password protected but if you want to see how it is done, there are other VIs from OpenG and others which do the same and are not password protected.

 

The second is slightly more complex, but there is a ready made VI in the Connectivity->WebService->Conversion palette, aptly named PNG Data to LV Image.vi.

 

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 2 of 13
(4,972 Views)

Thanks for the quick response 

I have tried from the web exemple without succes. I receive from the webservice the base64 data and I would like to convert this data to image in labview.base64base64frontfrontProgrammeProgramme

0 Kudos
Message 3 of 13
(4,895 Views)

I refuse to debug images. LabVIEW VIs may look like images, but they are much more than that. A lot of information is not deductible from an image. Your VI looks to big to start with with stacked sequences inside case structures insides case structures, inside..... You have a control labeled "(decoded)" but it is connected to the same wire as the encoded base64 string, so totally useless to use as image debugging feature. If you had attached the VI with meaningful default data, it wouldn't matter as much, but you didn't, so you made it impossible for anyone else to help you in this.

 

You clear the error from the Base64 decode function. If there is an error out it usually means something, and clearing the error doesn't make the function perform anyways, it just hides that there was an error to begin with and the function therefore was unable to do what it is supposed to do, for instance because the data was not correctly encoded to begin with. Just because you label a control to say that it does contain Base64 data doesn't mean that it really contains such data. There could be many reasons why it doesn't, such as wrong documentation, transmission errors, you understanding something wrong, etc.

 

Ohh and if you attach the real VI, please do a "Save for previous version". Not everyone uses the latest and greatest version of LabVIEW on here and I have a strong suspicion that that will only increase in the future.

 

Once the Base64 function can operate properly and the decoded data really is a PNG data stream, your VI will magically start to work. Until then it is debugging time, which you have to do on your own if you are not able to attach the real VI (with default data or a text file containing that default data).

 

And when you attach your VI, please don't forget to do a "Save for previous version". Not everyone is using the latest and greatest version on here, and I have a strong suspicion that that will increase in the future.

 

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 4 of 13
(4,887 Views)

wiebeCARYA_0-1651483195376.png

 

'image' doesn't seem to be a PNG. JFIF not a PNG file header, and there seem to be 6 bytes before that ( FFD8 FFE0 0010 )...

 

JFIF, JPEG File Interchange Format, Version 1.02 (loc.gov)

 

You need to read the manual on that interface. See what 'image' actually is.

 

Spoiler

 

...a jpeg file...

 

Convert the data to a JPG, and it will work better.

 

0 Kudos
Message 5 of 13
(4,841 Views)

@rolfk wrote:

 

The Base64 decoding is trivial to do. There is a function for that in the HTTP Client VI library. It's not on the palette directly but you can find it in vi.lib\httpClient. 

 oh, nice. 

I used to use https://forums.ni.com/t5/Example-Code/Fast-Base64-Encoder-Decoder-using-LabVIEW/ta-p/3503281?profile...

 

 

Spoiler

 

0 Kudos
Message 6 of 13
(4,828 Views)

I believe that the received data comes from a JPEG image, my only problem is to find the Labview function able to transform the Base 64 image code into an image in labview.

Please I will sent a sample of the code that I receive from the webservice

Regards

0 Kudos
Message 7 of 13
(4,716 Views)

It was you who originally claimed that it was a PNG stream but there is no need for any believes here. Wiebe showed you already that it is a JFIF stream, which is what is inside a JPEG image.

Unfortunately there is no direct equivalent to the PNG Data to Image function for JPEG. The simplest thing would be to write the Base64 encoded string in binary mode to a file and then read that file back. Direct in memory conversion is more involved and will require some low level tinkering that I think you should try to avoid.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 8 of 13
(4,710 Views)

@rolfk wrote:

Unfortunately there is no direct equivalent to the PNG Data to Image function for JPEG.


See the idea Add function to convert string to image - NI Community.

 

There's a link to a solution, but it seems quite complicated (involving several dlls).

 

I'd use .NET:

JPG To Pixmap From Memory.png

Note that the 'save' method doesn't save to file, but to the stream. This stream is a png, and is easily translated to a string in memory.

Message 9 of 13
(4,668 Views)

Actually there is a function that ships with the LabVIEW drivers for NI-XNET which does pretty much the same using .Net. It is at "examples\nixnet\projects\NI-XNET Ethernet\subVI\Video\JPEG\DOTNET - JPEG String to LabVIEW Image 2012 NIVerified.vi"

 

I think it is pretty much the same from this knowledge base article: https://forums.ni.com/t5/Example-Program-Drafts/Methods-for-converting-a-JPEG-data-string-stream-to-...

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 10 of 13
(4,646 Views)