- Code: Select all
Private Sub Command2_Click()
Dim nImageID As Long
If Twain1.TwainOpenDefaultSource() Then
InitScanConfig
Twain1.TwainSetCurrentResolution (300)
Twain1.TwainSetCurrentPixelType (TWPT_RGB) 'RGB
Twain1.TwainSetCurrentBitDepth (8) ' 24 bpp
nImageID = Twain1.TwainAcquireToGdPictureImage(Me.hwnd)
If nImageID <> 0 Then
If ChkRotat.Value = 1 Then Call Twain1.Rotate(Rotate90FlipNone)
If ChkBord.Value = 1 Then Call Twain1.CropBorders
Call DisplayNativeImage
Call Twain1.CloseImage(nImageID)
End If
Call Twain1.TwainCloseSource
If nImageID <> 0 Then MsgBox LoadResString(1060)
Else
MsgBox LoadResString(2400)
End If
End Sub
Private Sub InitScanConfig()
Twain1.TwainSetHideUI (ChkUI.Value)
Twain1.TwainSetIndicators (False)
If ChkAutoLum.Value = 1 Then
Twain1.TwainSetAutoBrightness (True)
Else
Twain1.TwainSetAutoBrightness (False)
Twain1.TwainSetCurrentBrightness (Slider1.Value)
End If
Twain1.TwainSetCurrentContrast (Slider2.Value)
Twain1.TwainEnableDuplex (False)
End Sub
Private Sub DisplayNativeImage()
Dim nViewRatio As Double
Picture1.Cls
nViewRatio = Picture1.ScaleHeight / Twain1.GetHeight
Call Twain1.DisplayImageOnHDC(Picture1.hdc, 1, 1, Twain1.GetWidth * nViewRatio, Twain1.GetHeight * nViewRatio, SmoothingModeAntiAlias)
Picture1.Refresh
DoEvents
End Sub
When we use our application with Canon, Plustek, HP, etc scanners, she work correctly. When we use it with different Brother Scanners (MFC 9840CDW or MFC 5460CN) the "Twain.TwainAcquireToGdPictureImage(Me.hwnd)" instruction send an "pile stack error" and the application stop. But with the same Brother scanner and pilot and with the sample demo of gdPicture, the application work correctly with these scanners.
