Delphi32.com - Home!
| Home/News | Downloads | Forums | D32 Magazine | Resources | Info and Facts |  
 
 Returning an image from a Web Server Application


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 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? TWebModule .WebModule WebActionItem Action(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;?
    

     



  << Previous Faq     Complete List     Next Faq >>  



 
 Hits/month  2,500,000+ 
 Downloads
 (Since May 2000)
 7,393,709 
 Total Files  6,023 
 Forum msgs  7,670 
 Articles/FAQs  70+/900+ 
Kylix
Tips n Tricks
FAQs
Knowledge Base
Bug Listings
Articles
Books
Newsgroups
Links
Submissions
Testimonials
Advertising
Contact Us
About Us
Search Amazon:
Top Selling Software at Amazon

| Home/News | Downloads | Forums | Resources | Info and Facts | Testimonials |
  Site Search:
 


Comments/Problems: Webmaster@delphi32.com
Copyright © 1998-2006, Delphi32.com. All rights reserved.
Terms of Use