Scan a multipage document to a TIFF file in memory

Example requests & Code samples for GdPicture Toolkits.
Post Reply
megamax
Posts: 4
Joined: Tue Oct 11, 2011 6:22 pm

Scan a multipage document to a TIFF file in memory

Post by megamax » Tue Oct 11, 2011 6:27 pm

Hello,

I need some help with this..

Scan a multipage document to a TIFF file in memory (not as a file). As a byte array Or memory stream. Is there any different way to do "acquire" vs the actual scan? (for the purpose of loading the thumnails)

Thanks!

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Scan a multipage document to a TIFF file in memory

Post by Loïc » Thu Oct 13, 2011 11:36 am

Hi,
Scan a multipage document to a TIFF file in memory (not as a file).

Code: Select all

    Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
        'Here we will scan in a 1bpp ccitt4 & 200 DPI from adf to multipage tif file
        Dim oGdPictureImaging As New GdPictureImaging
        Dim nImageCount As Integer
        Dim TiffID As Integer

        If oGdPictureImaging.TwainOpenDefaultSource(Me.Handle) Then
            nImageCount = 0
            oGdPictureImaging.TwainSetAutoFeed(True) 'Set AutoFeed Enabled
            oGdPictureImaging.TwainSetAutoScan(True) 'To  achieve the maximum scanning rate

            oGdPictureImaging.TwainSetResolution(200)
            oGdPictureImaging.TwainSetPixelType(TwainPixelType.TWPT_BW) 'Black & White
            oGdPictureImaging.TwainSetBitDepth(1) ' 1 bpp
            Do
                Dim ImageID As Integer = oGdPictureImaging.TwainAcquireToGdPictureImage(Me.Handle)
                If ImageID <> 0 Then
                    nImageCount = nImageCount + 1
                    If nImageCount = 1 Then
                        TiffID = oGdPictureImaging.TiffCreateMultiPageFromGdPictureImage(ImageID)
                    Else
                        oGdPictureImaging.TiffAppendPageFromGdPictureImage(TiffID, ImageID)
                    End If
                    oGdPictureImaging.ReleaseGdPictureImage(ImageID)
                End If
            Loop While oGdPictureImaging.TwainGetState > TwainStatus.TWAIN_SOURCE_ENABLED


            oGdPictureImaging.TwainCloseSource()
            oGdPictureImaging.TiffSaveMultiPageToFile(TiffID, "c:\multipage.tif", TiffCompression.TiffCompressionAUTO)
            oGdPictureImaging.ReleaseGdPictureImage(TiffID)
            MsgBox("Done !")
        End If
    End Sub
Is there any different way to do "acquire" vs the actual scan? (for the purpose of loading the thumnails)
Sorry but I do not understand.

Hope this helps !

megamax
Posts: 4
Joined: Tue Oct 11, 2011 6:22 pm

Re: Scan a multipage document to a TIFF file in memory

Post by megamax » Thu Oct 13, 2011 5:15 pm

Isn't this line for saving it to a file?

oGdPictureImaging.TiffSaveMultiPageToFile(TiffID, "c:\multipage.tif", TiffCompression.TiffCompressionAUTO)

I need to save this (the entire multipage tiff) as a stream or byte array WITHOUT saving it to a file first. I have seen a method called SaveAsByteArray which might work, but I am not sure how to save the entire multipage file, since one of the parameters is the ImageID.

As far as the 2nd question, scanners usually have two scanning modes, what I call "acquire", which is a quick scan just to generate a preview (really fast.. it might take 2 or 3 secs to swipe a full page), and the 2nd one which is the actual scan, where the full resolution image is generated. Since I am planning on having users select the images they want from the thumbnail control and then do the scan, It would be good if the user don't have to spend time waiting for a full scan before deciding what would the final pages be.

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Scan a multipage document to a TIFF file in memory

Post by Loïc » Fri Oct 14, 2011 3:39 pm

Isn't this line for saving it to a file?

oGdPictureImaging.TiffSaveMultiPageToFile(TiffID, "c:\multipage.tif", TiffCompression.TiffCompressionAUTO)

I need to save this (the entire multipage tiff) as a stream or byte array WITHOUT saving it to a file first. I have seen a method called SaveAsByteArray which might work, but I am not sure how to save the entire multipage file, since one of the parameters is the ImageID.
Yes, the SaveAsByteArray() or SaveAsStream() method create a multipage tiff.


For the second issue, to create a preview just scan using a low resolution. This is the way used by almost all drivers.

Kind regards,

Loïc

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest