community.borland.com

Article #15723: Returning an image from a Web Server Application

 Question and Answer Database

FAQ723D.txt - Returning an image from a Web Server Application

Category   :Internet/WEB
Platform   :All-32Bit
Product    :

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

Answer:
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 
property:



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 PJEG unit. ?procedure? TWebModule1.WebModule1WebActionItem1Action(Sender: TObject; Request: TWebRequest; Response: TWebResponse; ?var? Handled: Boolean); ?var? Jpg: TJpegImage; S: TMemoryStream; ?begin? Jpg := TJpegImage.Create; ?try? Jpg.LoadFromFile('test'); S := TMemoryStream.Create; ?try? Jpg.SaveToStream(S); S.Position := 0; Response.ContentType := 'image/jpeg'; Response.ContentStream := S; // Must be done prior to freeing the stream Response.SendResponse; ?finally? S.Free; ?end;? ?finally? Jpg.Free; ?end;? ?end;? 4/2/99 11:44:11 AM

Last Modified: 01-SEP-99