开发者

Response.WriteFile -- Write out a byte stream

开发者 https://www.devze.com 2023-01-17 05:01 出处:网络
Is is possible to write to t开发者_如何学JAVAhe http response stream from a dynamically created bitmap using the Response.Write/WriteFile without saving the image to the hard drive?You can use a Memor

Is is possible to write to t开发者_如何学JAVAhe http response stream from a dynamically created bitmap using the Response.Write/WriteFile without saving the image to the hard drive?


You can use a MemoryStream and assign it to Response.OutputStream, or simply use Response.OutputStream directly when saving the bitmap.

There is an example in the documentation on this page, though it simply saves the bitmap directly to the output stream:

// Set the correct content type, so browser/client knows what you are sending
Response.ContentType = "image/jpeg";
Response.Clear();

Bitmap bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb);
Graphics g = Graphics.FromImage(bmp);

bmp.Save(Response.OutputStream, ImageFormat.Jpeg);


If you have your bitmap stored in a byte[] you can also dump that directly into Response.BinaryWrite(myByteArray);, as long as you have your content-type, length and disposition set correctly (as mentioned by @arx).


How about Response.BinaryWrite?


Yes. Make sure you set the content-type correctly and it should work fine.

0

精彩评论

暂无评论...
验证码 换一张
取 消