.Net Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - More.Net Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 4th, 2007, 07:50 AM
JJKebab JJKebab is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 11 JJKebab User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 9 m 58 sec
Reputation Power: 0
Serving images using HTTPListener

I am using the HTTPListener object to serve requests for html documents. Everything seems straight forward. However I would also like to be able to dynamically create images based on requests.

How do I go about sending images (such as a png) from a picturebox through the HTTPListener. I already guessed I'll need to change MIME type, but how do I get the image into the output stream?

Thanks in advance!

P.S. I am using C#

Reply With Quote
  #2  
Old January 16th, 2007, 01:17 PM
JJKebab JJKebab is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 11 JJKebab User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 9 m 58 sec
Reputation Power: 0
Don't worry. I solved it myself

After much playing around, I got this. It may be useful for anyone else who is interested:

Code:
        protected virtual void ProcessRequest(HttpListenerContext Context)
        {

            HttpListenerRequest Request = Context.Request;
            HttpListenerResponse Response = Context.Response;

// This bit creates the image and is obviously unique to my app
            int xx = Convert.ToInt32(Request.QueryString["x"]);
            int yy = Convert.ToInt32(Request.QueryString["y"]);

            DrawMap(buff,xx,yy,594,339,gBumps);
            
//Save out image as file
            buff.Save("c:\\temp.png", System.Drawing.Imaging.ImageFormat.Png);

//Open image as byte stream to send to requestor
            FileInfo fInfo = new FileInfo("c:\\temp.png");
            long numBytes = fInfo.Length;

            FileStream fStream = new FileStream("c:\\temp.png", FileMode.Open, FileAccess.Read);

            BinaryReader br = new BinaryReader(fStream);

            byte[] bOutput = br.ReadBytes((int)numBytes);

            br.Close();

            fStream.Close();

            Response.ContentType = "image/png";
            Response.ContentLength64 = bOutput.Length;

            Stream OutputStream = Response.OutputStream;
            OutputStream.Write(bOutput, 0, bOutput.Length);
            OutputStream.Close();

        }

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - More.Net Development > Serving images using HTTPListener

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap