I made a mistake in my initial solution.
WebControls.Image
is just a
HTML
container for an image
URL
- you can't store the image data directly in it, you just store the reference (
URL
) to an image file. If you need to retrieve image data dynamically, the usual approach is to create an image handler that will handle the request and return the image as a stream that the browser can display. You can create
ASPX
page that will return image file as byte array with appropriate headers information, to get image you will be able to call this page like
imagemanager.aspx?imgid=31337
Then in your main page in
system.web.ui.webcontrols.image
control set
ImageUrl
property to your script path:
ctrlImage.ImageUrl = "imagemanager.aspx?imgid=31337";
Here is example of method to output you image in imagemanager.aspx:
private void TransmitBytes(byte[] bytes, string outFileName)
{
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + outFileName);
Response.AddHeader("Content-Length", bytes.Length.ToString());
Response.ContentType = "image/jpeg";
Response.BinaryWrite(bytes);
Response.End();
}
This should work :)
[Edit member="Tadit"]
Corrected formatting issues.
[/Edit]