views:

125

answers:

1

I created image from byte array

System.Drawing.Image newImage;
using (MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length))
{
       ms.Write(imageBytes, 0, imageBytes.Length);
       newImage = System.Drawing.Image.FromStream(ms, true);                
}

and now I need to have this image as a source for asp:Image (System.Web.UI.WebControls.Image). Is this possible as I know that conversion is impossible?

+1  A: 

Use the following code:

  System.IO.MemoryStream ms = new System.IO.MemoryStream();
  image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
  Response.ClearContent();
  Response.ContentType = "image/Gif";
  Response.BinaryWrite(ms.ToArray());


<asp:Image ID="Image1" runat="server" ImageUrl="~/pic.aspx"/>
MUG4N
Just a heads-up: If session state is enabled, browsers will be able to fetch only one image at a time due to locking issues. See **Concurrent Requests and Session State** here: http://msdn.microsoft.com/en-us/library/ms178581.aspx
Chris
Let's say this "saving code" is in Page_Load event of a page pic.aspx. Do I still call the same pic.aspx page as ImageUrl?
trnTash
Sorry you have to try that because honestly I have never done that before
MUG4N