LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read JPG function fails for some JPG files

Hello, 

 

I am having trouble opening a JPG file that I download from internet using datasocket.

Please refer to the attached code.

the function seems to work with some files but not other. 

I am providing 3 url as an example. the first two will work but the last one fails everytime:

 

http://media.digikey.com/Renders/Samsung%20Electro-Mechanics%20America/0805-(1.40)-CL-Series.jpg

http://media.digikey.com/Photos/CnC%20Tech/3220-10-0100-00.JPG

http://media.digikey.com/Photos/JST%20Photos/SM05B-PASS-TBT(LF)(SN).JPG

 

successful readingsuccessful readingfailed readingfailed reading

 

 

The windows image viewer can view the image saved on file ( but paint also fails to open the file ) 

I am wondering if the file is somehow being saved corrupt in some cases. 

 

I appreciate any help on this

 

thanks

AJ

 

Download All
0 Kudos
Message 1 of 9
(3,238 Views)

Addional note :

one difference between the files that work and the ones that does not is the size of the JPEG.. file

the ones that are working are <50KB of size while the one that failed is 257KB.

0 Kudos
Message 2 of 9
(3,236 Views)

When I download the file and save it to my desktop, the Read JPEG is able to read it just fine.

0 Kudos
Message 3 of 9
(3,204 Views)

I am not sure I understand what you mean by download the JPG. did you manually download it wia a web browser or usign the datasocket code I attached ?

the problem might be coming from the datasocket read function . the function outputs a string that I save as a binary file then read it with the open JPG function. this works with small sized images but not with relatively larger files... 

 

0 Kudos
Message 4 of 9
(3,199 Views)

Of course I downloaded it.  You said you had a problem with the downloaded JPEG file.

 

The JPEG file is just fine.

0 Kudos
Message 5 of 9
(3,190 Views)

thank you for clarifying.

Do you think this method of downloading an image using datasocket makes sense:

Capture.PNG

0 Kudos
Message 6 of 9
(3,184 Views)

The smaller files might work because they are read in a single call of Datasocket Read, whereas the larger JPG might require more than one read. You need to change your string output tunnel on the For Loop to index and then concatenate that string array otherwise you won't read the whole file. Secondly you can't terminate on the first successful read - you need to terminate on the timeout.

0 Kudos
Message 7 of 9
(3,151 Views)

@mam1nej wrote:

thank you for clarifying.

Do you think this method of downloading an image using datasocket makes sense:

Capture.PNG


Of course not! The [text] specifier at the end of the datasocket url tells the datasocket function that you are downloading a text file. That tells datasocket also that you want to have different transformations applied to the binary data stream such as EOL conversion from whatever LF, CR, CRLF combination inside the stream to the current platform, which under Windows is CRLF. jpg being highly binary is very sensitive to any bit change in the binary data stream.

 

Remove that appendix and things should look much better (and a binary compare of the two files will certainly show differences).

Rolf Kalbermatter
My Blog
0 Kudos
Message 8 of 9
(3,144 Views)

thanks for the feedback. 

I was using the [text] to avoid getting error 42 on datasocket read, as described here 

http://digital.ni.com/public.nsf/allkb/27272FE3A32C334286257612004D9153

 

the datasocket read throws a 42 error if I use the URL without the [text] identifier

0 Kudos
Message 9 of 9
(3,129 Views)