Board index » cppbuilder » Loading a JPEG or GIF from a WebServer and into TImage

Loading a JPEG or GIF from a WebServer and into TImage

I basically want to load a JPEG-file from
http://www.anyserver.com/anyfile.jpg and display the image in a TImage
component in my TForm.

The server only supports HTTP.

I could use TCppWebBrowser, but it dosen't quite fit with my GUI, so I'd
rather use TImage.

Any suggestions?

 

Re:Loading a JPEG or GIF from a WebServer and into TImage


Quote
> I basically want to load a JPEG-file from
> http://www.anyserver.com/anyfile.jpg and display the image in a TImage
> component in my TForm.

> The server only supports HTTP.

> I could use TCppWebBrowser, but it dosen't quite fit with my GUI, so I'd
> rather use TImage.

Sorry for the delayed response.

I recommend that you use the HTTP client component from the INDY component
suite. Point it to your jpeg URL, and read the contents into a memory
stream. Once you get the JPEG contents into a memory stream, you can do
this:

// reposition the stream (very important!
stream->Position = 0;

// Create a TJPEGImage, and tell it to load from the memory stream.
std::auto_ptr<TJPEGImage> JImage(new TJPEGImage());
JImage->LoadFromStream(stream);

// Now that we have a TJEGImage, we can use Assign to
// copy that image into a TImage.
MyImage->Width  = JImage->Width;
MyImage->Height = JImage->Height;
MyImage->Picture->Assign(JImage.get());

Harold Howe [TeamB]
http://www.bcbdev.com

Other Threads