Loading Image from WebInputStream


#1

Hey guys,

Sometime recently I noticed that loading images from webInputStreams stopped working for me.

Haven’t dug into it, so it may be an intentional change or something I am missing, but I noticed that this code stopped working:

ScopedPointer<InputStream> in (urlToHit.createInputStream(false, nullptr, nullptr, String::empty, 2000) );  
mostRecentImage = ImageFileFormat::loadFrom ( *in.get() );

However, replacing it with a version that reads the stream into a MemoryBlock and then loads was fine:

 ScopedPointer<InputStream> in (urlToHit.createInputStream(false, nullptr, nullptr, String::empty, 2000) );
 MemoryBlock dest;
 int size = in->readIntoMemoryBlock(dest);
 mostRecentImage = ImageFileFormat::loadFrom(dest.getData(), size);

Anyway, I assume the first is intended to work as well, since the function still exists, but it definitely gets stuck trying to create the image (format->decodeImage() is returning invalid images).

I tried it with both JPEG and PNG, and with JUCE_USING_COREIMAGE_LOADER set to 1 and 0. Same result. This is on mac, if that matters.


#2

Could be that the image reading code tries to seek within the stream, and HTTP streams are really bad at seeking…?


#3

Seems possible.
I had assumed that somewhere under the hood the code would just read the entire stream first and then try to parse it.

In any event, the alternative code works fine so I’m not sweating it, but you should probably remove the ability to give it a web stream directly if it’s not likely to work.

Also, it did work until recently.