开发者

Refining my previous "bytearray to image asp.net" question

In an aspx page you have an <image> control, waiting to be "fed" an image. In the code-behind of that page, you have (It's simply there. It isn't relevant how it got there) an array of bytes representing an image. I want the image contr开发者_C百科ol (or any alternative you suggest) to present the picture represented in that array. HOW? Code example?


You can use the canvas tag, and to make it cross-browser you can look at the excanvas project, at http://code.google.com/p/explorercanvas/

In this page you can look at the section about embedding an image via the data: url, as that may be what you are looking for. https://developer.mozilla.org/En/Canvas_tutorial/Using_images


You write the byte array to disk or to your database. In the source of the image control, you put a HTTP handler (see the answers to your "bytearray to image asp.net" question) with some query string containing information which allows you to retrieve the file or database row.


A control can't really render an image all by itself. Controls normally render text that gets inserted into the HTML that comprises a page.

To dynamically generate an image from a byte array, you should instead use an HttpHandler. The Handler can simply write the bytes to the output stream using Response.Write(), and then set the content type to the appropriate MIME type.

You would usually decide which image to create based on an argument in a query string that gets passed to your Handler.

Generic Handlers (.ashx files) are an easy way to do this.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜