locked
Convert Stream to Asp.net Image control RRS feed

  • Question

  • hi ,

        I have System.Web.UI.Webcontrols Image control. I read the image from Database as Memory Stream. I want to map memory Stream to Image control.. I tried lot.... but i didn't got a solution...

    Tuesday, June 12, 2012 5:21 AM

Answers

  • Hi santoshkumar,

    I don't think your problem is relate pre-SharePoint production. So, I think you should ask the question on ASP.Net forum.

    After my search, there is a method , you can refer to it.

     private void byteArrayToImage(byte[] byteArrayIn)
        {
            System.Drawing.Image newImage;
     
            string strFileName = GetTempFolderName() + "yourfilename.gif";
            if (byteArrayIn != null)
            {
                using (MemoryStream stream = new MemoryStream(byteArrayIn))
                {
                    newImage = System.Drawing.Image.FromStream(stream);
     
                    newImage.Save(strFileName);
     
                    img.Attributes.Add("src", strFileName);
                }
     
                lblMessage.Text = "The image conversion was successful.";
            }
            else
            {
                Response.Write("No image data found!");
            }
        }

    Thanks,

    Jack


    Thursday, June 14, 2012 5:43 AM
    Moderator