Главная страница | назад

Article #19710: Streaming an image from a webserver application

 Question and Answer Database

     FAQ: FAQ4710C - Streaming an image from a webserver application
Category: Internet/WEB
Platform: All-32Bit
 Product: C++Builder3.x,   C++Builder4.x,   


How can I embed a graphic into an HTML document produced by my
Web Server application?


Here is an example of how to embed a graphic into your web 
contents.  This example actually demonstrates how to return 
a jpeg using code.  Of course you could also simply put a 
reference to an actual jpeg in the  tag.  In 
this example the browser will "hit" the  tag and 
go back to the server to get the image and we are simply using 
the DLL to return what could be a dynamic image.

1. Use a page producer with the following for the HTMLDoc 

This is a test
2. Now set up an Action with the PathInfo of /picture and return the following: (make sure your app "uses" the TJEG unit. void __fastcall TWebModule1::WebModule1WebActionItem1Action(TObject *Sender, TWebRequest *Request, TWebResponse *Response, bool &Handled) { TJPEGImage *jpg; TMemoryStream *ms; jpg = new TJPEGImage(); try { jpg->LoadFromFile("test.jpg"); ms = new TMemoryStream(); try { jpg->SaveToStream(ms); ms->Position = 0; Response->ContentType = "image/jpeg"; Response->ContentStream = ms; Response->ContentLength = ms->Size; // Must be done prior to freeing the stream Response->SendResponse(); } __finally { delete ms; } } __finally { delete jpg; } } 8/4/99 11:56:44 AM

Last Modified: 01-SEP-99