Page 1 of 1

saving a vintasoft image to a database table

Posted: Thu Aug 21, 2014 4:08 pm
by BillG
i have a sql server database table named MemberPhotos. It has a field with a type of varbinary(MAX). Can I save a VintasoftImage to it or do I have to convert it to something else first?

Bill

Re: saving a vintasoft image to a database table

Posted: Thu Aug 21, 2014 6:31 pm
by Alex
Hello Bill,

You need save image as a file to a MemoryStream object, get byte array from MemoreStream object and save byte array to a field of database table. Here is an example:

Code: Select all

byte[] GetVintasoftImageAsByteArray(VintasoftImage image)
{
    using (MemoryStream mem = new MemoryStream())
    {
        image.Save(mem, new JpegEncoder());
        
        byte[] byteArray = new byte[mem.Length];
        mem.Position = 0;
        mem.Read(byteArray, 0, mem.Length);

        return byteArray;
    }
}
Best regards, Alexander