saving a vintasoft image to a database table

Questions, comments and suggestions concerning VintaSoft Imaging .NET SDK.

Moderator: Alex

Post Reply
BillG
Posts: 47
Joined: Fri Oct 10, 2008 3:52 pm

saving a vintasoft image to a database table

Post by BillG » Thu Aug 21, 2014 4:08 pm

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

Alex
Site Admin
Posts: 1462
Joined: Thu Jul 10, 2008 2:21 pm

Re: saving a vintasoft image to a database table

Post by Alex » Thu Aug 21, 2014 6:31 pm

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

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest