Pages

Social Icons

Wednesday 9 November 2011

Retrieve the Image From the Database


If we want to retrive the image from the database then first we pick the image from the database and then convert it into the image :

Here I am store the image in to database in an byte array now I am converting that byte array in to an image :

Image MyImage = ConvertImage(imageData);

public static Image ConvertImage(object value)
{
     byte[] img;
     Image newImage;
     img = (byte[])value;

     //Read image data into a memory stream
     using (MemoryStream ms = new MemoryStream(img, 0, img.Length))
     {
        ms.Write(img, 0, img.Length);

        //Set image variable value using memory stream.
        newImage = Image.FromStream(ms, true);
     }
     return newImage;
}

picturebox1.Image = MyImage;

No comments:

Post a Comment