vivante Posted May 18, 2012 Report Share Posted May 18, 2012 Hi guys, I have to manage PNG images that don't come from a file, but from a TCP/IP connection. usually I use PNG data to LabVIEW image.vi to convert them into an image data cluster, but this time PNG images are different, I think. These images can be opened with all software without issues, anyway in LabVIEW PNG data to LabVIEW image.vi returns error code 1097. Unfortunately, saving received strings into temporary files is not possible in my app, so I need to convert them on the fly. have you ever seen this error? attached you find a sample code and an image sample. regards, Claudio image conversion.zip Quote Link to comment
Darin Posted May 18, 2012 Report Share Posted May 18, 2012 My experience has been that the string based PNG VIs can not handle 32-bit images (ie. containing alpha info). The file based VIs are more robust, but still do not handle transparency very well. I have rolled my own PNG VIs, but simply writing the string to a temporary file then reading it is usually sufficient. Quote Link to comment
asbo Posted May 18, 2012 Report Share Posted May 18, 2012 If speed/space is the limiting factor in writing out to a temporary file, a RAM-disk may be a happy workaround for you. Quote Link to comment
vivante Posted May 20, 2012 Author Report Share Posted May 20, 2012 Thank you for your post! So in your experience there is no way to manage a string containing an image in its native format WITHOUT storing and loading it. In my opinion, this is a bad workaround expecially if your application has to manage many pictures, but it seems to be the only one.. Quote Link to comment
JamesMc86 Posted May 21, 2012 Report Share Posted May 21, 2012 There can be some different structures although anything which is PNG should be readable by a PNG reader (if that makes sense). I will take a proper look at the code myself later but I made a VI to pull the PNG files appart to see what is inside, maybe it will identify some differences? You can find the code at https://decibel.ni.com/content/docs/DOC-19620 1 Quote Link to comment
asbo Posted May 21, 2012 Report Share Posted May 21, 2012 Your PNG file is actually causing an exception in what I assume are CLNs to functions in the LabVIEW library. You should submit a copy of the PNG file to NI support so they can correct their library. I'd be interested in seeing the file if it's something you can make public. Quote Link to comment
vivante Posted May 21, 2012 Author Report Share Posted May 21, 2012 PNG sample is included in image conversion.zip (my first post). Quote Link to comment
Darin Posted May 21, 2012 Report Share Posted May 21, 2012 There are a variety of formats supported by PNG, my version of the PNG suite contains 157 different files. The File-based VIs will handle 154 of the 157 files. The string-based one will handle 59 of the 157. Clearly NI has written/licensed a nearly compliant PNG reader, why it is not using the same one in both cases is beyond me. I was annoyed when I first saw the string based VIs hidden deep in the palettes (having written my own). After some quick testing the crappiness (technical term) was soon apparent so I was glad to have made the effort. The simple .NET solution may be an option for you if you are on a Windoze machine. 2 Quote Link to comment
vivante Posted May 25, 2012 Author Report Share Posted May 25, 2012 Thank you! I will try your .NET solution. Quote Link to comment
Rolf Kalbermatter Posted May 28, 2012 Report Share Posted May 28, 2012 There are a variety of formats supported by PNG, my version of the PNG suite contains 157 different files. The File-based VIs will handle 154 of the 157 files. The string-based one will handle 59 of the 157. Clearly NI has written/licensed a nearly compliant PNG reader, why it is not using the same one in both cases is beyond me. Well, I'm pretty sure they use the libpng kernel for the PNG support in both cases. However as you have certainly found out the interface to libpng is not simple and the possible formats are not trivial to map to a pixel based image format like NI is using. In fact some of the features of PNG are impossible to maintain with a single 2D pixmap and an optional alpha channel. To support memory streams requires quite a bit more work too as libpng supports accessing files directly but requires extra work to support memory streams instead. So it's very easy to take a few shortcuts in one case and end up with less support for the more exotic PNG formats than when using file based input/output. Quote Link to comment
MikaelH Posted May 29, 2012 Report Share Posted May 29, 2012 Maybe some of the other LabVIEW.exe-dll calls can do the trick, but it's hard to figure out how to use is. Quote Link to comment
asbo Posted May 29, 2012 Report Share Posted May 29, 2012 I would bet dollars to donuts that those are the functions employed by the PP'd VI and one of them is throwing the exception. Based on rolf's input, I would probably expect that there won't be much you can do about it while using only a pixmap. Quote Link to comment
vivante Posted June 12, 2012 Author Report Share Posted June 12, 2012 how do you convert an image, e.g. a jpeg one, from its binary format to a IMAQ image? I do two steps: first I pass from the binary string to an "image data" cluster and then I pass to a IMAQ image with the code below. Do you know a better way? Quote Link to comment
Rolf Kalbermatter Posted June 13, 2012 Report Share Posted June 13, 2012 how do you convert an image, e.g. a jpeg one, from its binary format to a IMAQ image? I do two steps: first I pass from the binary string to an "image data" cluster and then I pass to a IMAQ image with the code below. Do you know a better way? Your description is not entirely clear. When you say "I pass from the binary string to an "image data" cluster" you mean that you have the JPG/PNG Data to LV Image in that stream? If so there is to my knowledge a way to do the opposite for the JPG case with the IMAQ Flatten Image to String function but not in the direction you are looking for as the use of the IMAQ Flattten Image Option function and the standard LabVIEW Flatten and Unflatten functions is unfortunately also not a solution since the Flatten adds extra info to the compressed data stream, that the Unflatten seems to expect (although it seems someone in the NI forums had some success with using the resulting data stream as normal JPEG stream, until he moved to LabVIEW 64 bit and got bad results). Quote Link to comment
vivante Posted June 13, 2012 Author Report Share Posted June 13, 2012 ah yes, I use PNG Data to LV Image and some .NET code to convert a jpeg binary string to a Image data cluster and this is my step 1. Step 2 is shown in the previous post. I think we are all agree that this solution is not nice. At the moment, is the only one I know... 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.