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 control (or any alternative you suggest) to present the picture represented in that array. HOW? Code example?

- 1,655
- 5
- 28
- 42
-
2You might want to choose a more suitable title. – Heinzi Nov 16 '09 at 08:52
3 Answers
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

- 41,583
- 10
- 86
- 166
-
Good idea. Note, however, that data url are not supported in Internet Explorer <= 7. IE8 support it, but only for data up to 32KB, see http://en.wikipedia.org/wiki/Data:_URL – Heinzi Nov 16 '09 at 08:28
-
@Heinzi - Most gifs should be under 32k, but I was trying to show an alternative, as that seems to be desired. It isn't perfect, but it may meet his needs. – James Black Nov 16 '09 at 08:33
-
@James: Sure, I understand that. +1, by the way, since I completely forgot about data:url. :-) – Heinzi Nov 16 '09 at 08:51
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.
-
-
It is impossible to embed the image in the page. The browser will always send two separate requests. – Pete Nov 16 '09 at 08:00
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.

- 18,448
- 3
- 51
- 66