VBA 및 WIA (Windows Image Acquisition Library)를 사용하여 ADF에서 스캔하려고합니다. ADF에 페이지가로드되어 있는지 확인하여 다른 페이지를 스캔할지 여부를 확인하려고합니다. 이 함수는 Windows 7 (내 dev 컴퓨터)에서는 잘 작동하지만 Windows XP에서는 그렇지 않습니다 (프로덕션 컴퓨터). MS가 비스타를 공개했을 때 MS가 WIA에 약간의 변경을가 했으므로이 문제의 근원 일 수있다.ADF에 페이지가로드되어 있어도 WIA 문서 처리 상태가 0을 반환합니다.
필자의 질문에 충분한 컨텍스트를 제공하기 위해 전체 함수 호출을 포함 할 것입니다. 이 함수는 필자가 작성한 클래스 모듈의 일부이므로 클래스 모듈 내의 다른 함수를 참조합니다. 간결함을 위해서, 나는 다른 기능들을 빼 놓았지만 요청이 있으면 기꺼이 게시 할 것이다.
'Windows Imaging Acquisition (WIA) Constants
Private Const wiaFormatBMP As String = "{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}"
Private Const wiaFormatGIF As String = "{B96B3CB0-0728-11D3-9D7B-0000F81EF32E}"
Private Const wiaFormatJPEG As String = "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}"
Private Const wiaFormatPNG As String = "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}"
Private Const wiaFormatTIFF As String = "{B96B3CB1-0728-11D3-9D7B-0000F81EF32E}"
Public Function ScanPage(Optional ShowScanningWizard As Boolean = True, _
Optional OverWrite As Boolean = False, _
Optional AppendToTiff As Boolean = True, _
Optional DocType As scanDocType = scanAuto, _
Optional HRes As Integer = 150, _
Optional VRes As Integer = 150, _
Optional width As Double = 8.5, _
Optional height As Double = 11, _
Optional UseADF As Boolean = False) As Boolean
'Windows Imaging Acquisition (WIA) Constants
Const ScannerDeviceType = 1
Const wiaIntentColor As Long = 1
Const wiaIntentGray As Long = 2
Const wiaIntentBlackWhite As Long = &H10004 '&H4 = IntentBlackWhite + &H10000 = Minimize Size '&H20000'131072
Dim cd As Object 'WIA.CommonDialog
Dim dev As Object 'WIA.Device
Dim ip As Object 'WIA.ImageProcess
Dim Prop As Object 'WIA.Property
Dim img As Object 'WIA.ImageFile
Dim Intent As Long
Dim MorePages As Boolean
On Error GoTo Err_ScanPage
ScanPage = False
'Verify scanned page can be saved
If Len(m_sFileName) = 0 Then
Err.Raise 5, , "Scan Aborted - No filename provided"
ElseIf IsTiff And AppendToTiff Then
'we're ok
ElseIf m_bFileExists And Not OverWrite Then
Err.Raise 58 'File already exists
End If
Set cd = CreateObject("WIA.CommonDialog")
Set dev = cd.ShowSelectDevice(ScannerDeviceType)
Set ip = CreateObject("WIA.ImageProcess")
'Set up conversion filter
ip.Filters.Add ip.FilterInfos("Convert").FilterID
ip.Filters(ip.Filters.Count).Properties("FormatID").Value = FileFormat
Select Case FileFormat
Case wiaFormatJPEG
ip.Filters(ip.Filters.Count).Properties("Quality").Value = 85
Case wiaFormatTIFF
'IP.Filters(IP.Filters.Count).Properties("Compression").Value = "CCITT4"
End Select
'Set intent for current document
If DocType <> scanAuto Then m_eScanType = DocType
If m_eScanType = scanDocument Then
Intent = wiaIntentBlackWhite 'wiaIntentGray
Else
Intent = wiaIntentColor
End If
DoEvents
If ShowScanningWizard Then
Set img = cd.ShowAcquireImage(ScannerDeviceType, , , FileFormat)
Else
With dev.items(1)
.Properties("Current Intent").Value = Intent
.Properties("Horizontal Resolution").Value = HRes
.Properties("Vertical Resolution").Value = VRes
.Properties("Horizontal Extent").Value = HRes * width
.Properties("Vertical Extent").Value = VRes * height
If m_eScanType = scanDocument Then
'Darken documents a bit so that handwriting is easier to see
' * Brightness is a value between -127 and +127
' * -45 was reached through trial and error and was tested on
' a CanoScan LiDE 20 flatbed scanner
.Properties("Brightness").Value = -45
End If
End With
On Error Resume Next
' For Each Prop In dev.items(1).Properties
' Debug.Print Prop.PropertyID, Prop.Name, Prop.Value
' Next Prop
'Scan the image
If UseADF Then
MorePages = True
For Each Prop In dev.Properties
Select Case Prop.PropertyID
Case 3087 'Document Handling Select (1 = ADF)
MorePages = MorePages And (Prop.Value = 1)
Case 3088 'Document Handling Status (1 = Page ready in ADF)
MorePages = MorePages And (Prop.Value = 1)
End Select
Next Prop
If MorePages Then Set img = cd.ShowTransfer(dev.items(1), , True) ' dev.Items(1).Transfer()
Else
Set img = cd.ShowTransfer(dev.items(1), , True)
End If
If Err.Number <> 0 Then
'User canceled the scan (most likely cause of error)
Err.Clear
ScanPage = False
GoTo Exit_ScanPage
End If
On Error GoTo Err_ScanPage
End If
If img Is Nothing Then GoTo Exit_ScanPage
'Convert to proper format
Set img = ip.Apply(img)
If IsTiff And AppendToTiff Then
m_iNumPages = m_iNumPages + 1
If m_iNumPages = 1 Then
'ReDim Preserve throws an error if the array is currently empty
ReDim m_sFNames(1 To 1)
Else
ReDim Preserve m_sFNames(1 To m_iNumPages)
End If
m_sFNames(m_iNumPages) = TempFileName(TempFilesPath, "tif")
img.SaveFile m_sFNames(m_iNumPages)
SaveToMultiTiff
m_bFileExists = True
ExtractPages
Else
If m_bFileExists And OverWrite Then Kill m_sFileName
img.SaveFile m_sFileName
m_iNumPages = 1
m_bFileExists = True
End If
ScanPage = True
Exit_ScanPage:
Exit Function
Err_ScanPage:
Select Case Err.Number
Case Else
LogError Err.Number, Err.Description, "ScanPage", "clsScan"
End Select
Resume Exit_ScanPage
End Function
안녕하세요, 귀하의 수업에 관련된 다른 기능들에 답변 해 주신 귀하의 질문에, 가능한 경우 그 사본을보고 싶습니다. 고마워, Jeroen –
@mrdevis : 다른 많은 의존성이 끝납니다. 원래 내가 다른 부분을 보여 주겠다고 제안한 이유는 잠재적 인 문제 해결사를 돕는 것이 었습니다. 이후로 나는 다른 모든 기능과 의존성을 게시하는 데 어려움을 겪지 않으므로 내 자신의 문제를 해결했습니다. vba 또는 wia에서 스캔하는 것과 관련하여 특정 질문이있는 경우 자신의 질문을 게시하는 것이 좋습니다. – mwolfe02