Pages

Social Icons

Wednesday 9 November 2011

Save the Image in to database


Here is a code which we can use for storing the image into database for this we can convert the image into a byte array and then store that array in to data base. The method is as follows:
 
byte[] imageData = CreateImage.convertPicBoxImageToByte(pb1);
 
public static byte[] convertPicBoxImageToByte(System.Windows.Forms.PictureBox pbImage)
{
    System.IO.MemoryStream ms = new System.IO.MemoryStream();
    pbImage.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
    return ms.ToArray();
}

Now save that imageData variable in database as a normal way.

No comments:

Post a Comment