tags:

views:

40

answers:

1

Hello, I want to extend a web server which is only able to handle RPC handling now. The web server is written in C#. It provides a abstract handler function like following:

public string owsHandler(string request, string path, string param,
                                      OSHttpRequest httpRequest, OSHttpResponse httpResponse)

And I wrote following code to handle image files:

Bitmap queryImg = new Bitmap(path);
System.IO.MemoryStream stream = new System.IO.MemoryStream();
queryImg.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
queryImg.Dispose();
byte[] byteImage = stream.ToArray();
stream.Dispose();
return Convert.ToBase64String(byteImage);

And I test it in the browser, the image is returned but the image dimension info is missed. Shall I add something more to the code? Or is any general way to server static files? I do not want to serve it in a ASP.net server.

Thanks

A: 

Don't try to load the file into a bitmap image in memory, just serve it as is.

return Convert.ToBase64String(File.ReadAllBytes(path));
Sam
Hi, but my bitmap is dynamically created, so I am afraid this method does not work.
xiao
@Turtle, I'm confused. In the title of the post you said *static* file and in your code sample you load the bitmap from a path. How is it dynamically created?
Sam
@Sam, Sorry, I did't clearly describe my problem. At first, I think it is same as serving static files. Late, I noticed that I need to generate the pictures dynamically.
xiao
@Turtle, then I would recommend asking a new question with a correct title and example. Good luck.
Sam