Img Compression before Save() to SQL DB

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

Moderator: Alex

Post Reply
htaylor
Posts: 5
Joined: Sun Aug 30, 2009 9:56 am

Img Compression before Save() to SQL DB

Post by htaylor » Sun Aug 30, 2009 11:56 pm

I have this working but saving to a DB over the network is very slow (30 sec) even at 72 d.p.i. unless the lowest scanner settings are selected. No matter what resolution the user scans at I want to force 8-bit grayscale at 72 d.p.i. THEN compress the file to speed things up.

Does any one have any compression code?

I have been looking but it has eluded me.

htaylor
Posts: 5
Joined: Sun Aug 30, 2009 9:56 am

Re: Img Compression before Save() to SQL DB

Post by htaylor » Mon Aug 31, 2009 6:12 am

For those interested I have decided not to allow user storage in the database as there is nothing to prevent the storage of illegal images. You may wish to re-think DB storage if you have a commercial application - could be bad for the Corporate image if it hit the headlines a child molester used your tools and database to store bad pictures.

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

Re: Img Compression before Save() to SQL DB

Post by Alex » Mon Aug 31, 2009 8:21 am

Hello Taylor,

Here is a snippet of code that saves images to stream in PDF format:

Code: Select all

Public Sub ScanWithUI()
    Dim mem As MemoryStream = Nothing
    VSTwain1.AppProductName = "MyTwainApplication"
    Try
        VSTwain1.StartDevice()
        VSTwain1.SelectSource()
        VSTwain1.ShowUI = true
        VTwain1.MaxImages = 1
        Dim firstImage As Boolean = True
        While VSTwain1.AcquireModal()
            If firstImage Then
                ' Create memory stream and place the first image to it
                mem = VSTwain1.GetImageAsStream(0, ImageFileFormat.PDF)
                firstImage = False
            Else
                ' Add second and next images to the stream
                VSTwain1.SaveImageToStream(0, mem, ImageFileFormat.PDF)
            End If
        End While
    Catch ex As TwainException
        MsgBox ex.Message
    Catch ex As ImagingException
        MsgBox ex.Message
    End Try
    ...
    ' Uploading stream data to server or doing something else...
    ...
End Sub
Also please read description of the SaveImageToStream method in documentation.

Best regards, Alexander

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests