9 Aug 2009

Convert Image To ByteArray

Image Table
CREATE TABLE [dbo].[Image_Table]
(
[Img_ID] [bigint] IDENTITY(1,1) NOT NULL,
[Image_Name] [image] NULL,
)


How To Convert Image To Byte Array
When you want to save image in database.It must save it as byte array.
The next function convert image to byte array:

public byte[] imageToByteArray(System.Drawing.Image img)
{
MemoryStream ms = new MemoryStream();
img.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
return ms.ToArray();
}

0 comments: