I was looking for a way to scan using .net. Found such a script
This script works correctly with the Brother 7057 and with the Canon MF 3228
Option Explicit
Const ScannerDeviceType = 1
Const ColorIntent = 1
Const wiaFormatJPEG = "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}"
Dim objDeviceManager
Dim objDeviceInfos
Dim objDevice
Dim objImageFile
Dim objImageProcess
Dim strPath2Save
Dim strFormat
Dim intQuality
Dim intDPI
Dim intHorizontalSize
Dim intVerticalSize
strPath2Save = "D:\MyImage.jpg" ' Полное имя файла для сохранения
strFormat = wiaFormatJPEG ' Формат файла — *.jpg
intQuality = 85 ' Качество jpg
intDPI = 150 ' Разрешение — 150 dpi
Set objDeviceManager = WScript.CreateObject("WIA.DeviceManager")
Set objDeviceInfos = objDeviceManager.DeviceInfos
If objDeviceInfos.Count > 0 Then
Set objDevice = WScript.CreateObject("WIA.CommonDialog").ShowSelectDevice(ScannerDeviceType, False, False)
If Not objDevice Is Nothing Then
With objDevice
With .Items(1)
With .Properties
.Item("6146").Value = ColorIntent
.Item("6147").Value = intDPI
.Item("6148").Value = intDPI
.Item("6149").Value = 0
.Item("6150").Value = 0
.Item("6151").Value = 1240
.Item("6152").Value = 1748
End With
Set objImageFile = .Transfer()
Set objImageProcess = WScript.CreateObject("WIA.ImageProcess")
With objImageProcess
With .Filters
.Add objImageProcess.FilterInfos("Convert").FilterID
With .Item(1).Properties
.Item("FormatID").Value = strFormat
.Item("Quality").Value = intQuality
End With
End With
Set objImageFile = .Apply(objImageFile)
End With
End With
End With
With WScript.CreateObject("Scripting.FileSystemObject")
If .FileExists(strPath2Save) Then
.DeleteFile strPath2Save
End If
End With
objImageFile.SaveFile strPath2Save
WScript.Echo "Complete."
Set objDevice = Nothing
Else
WScript.Echo "Cancel scanning by user"
End If
Else
WScript.Echo "No connected devices"
End If
Set objDeviceManager = Nothing
Set objDeviceInfos = Nothing
WScript.Quit 0
Translated this scrip to vb.net
With the Broteher 7057 everything works fine
With the Canon MF 3228, when you try to scan in color, you get a black and white image with the entire scanned area (1240x1748), and if you try to scan in grayscale, you will get a gray drawing, but half of the scan area (620x874)
Please, help me with my problem
PS
English - is not my first languge, sorry
For work this in vb.net need wiaaut.dll
PSS
Code on vb.net
Public Sub Scan()
Const ScannerDeviceType = 1
Const ColorIntent = 1
Const wiaFormatJPEG = "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}"
Dim strPath2Save As String = "D:\MyImage.jpg"
Dim strFormat As String = wiaFormatJPEG
Dim intQuality As Integer = 85
Dim intDPI As Integer = 150
Dim intHorizontalSize As Integer = 1240
Dim intVerticalSize As Integer = 1748
Dim objDeviceManager As WIA.DeviceManager = CreateObject("WIA.DeviceManager")
Dim objDeviceInfos = objDeviceManager.DeviceInfos
If objDeviceInfos.Count > 0 Then
Dim objDevice = CreateObject("WIA.CommonDialog").ShowSelectDevice(ScannerDeviceType, False, False)
If Not objDevice Is Nothing Then
objDevice.Items(1).Properties.Item("6146").Value = ColorIntent
objDevice.Items(1).Properties.Item("6147").Value = intDPI
objDevice.Items(1).Properties.Item("6148").Value = intDPI
objDevice.Items(1).Properties.Item("6149").Value = 0
objDevice.Items(1).Properties.Item("6150").Value = 0
objDevice.Items(1).Properties.Item("6151").Value = intHorizontalSize
objDevice.Items(1).Properties.Item("6152").Value = intVerticalSize
Dim objImageFile As WIA.ImageFile = objDevice.Items(1).Transfer()
Dim objImageProcess As WIA.ImageProcess = CreateObject("WIA.ImageProcess")
'objImageProcess.Filters.FilterInfos("Convert").FilterID()
'objImageProcess.Item(1).Properties.Item("FormatID").Value = strFormat
'objImageProcess.Item(1).Properties.Item("Quality").Value = intQuality
' objImageFile = objImageProcess.Apply(objImageFile)
If CreateObject("Scripting.FileSystemObject").FileExists(strPath2Save) Then
CreateObject("Scripting.FileSystemObject").DeleteFile(strPath2Save)
End If
objImageFile.SaveFile(strPath2Save)
objDevice = Nothing
Else
End If
Else
End If
objDeviceManager = Nothing
objDeviceInfos = Nothing
End Sub
What I have tried:
1) I called the technical support of Canon, but they do not deal with such problems
2) If you run the script as a scan.vbs file from the program itself, it works, but there is no feedback from the program and many other errors may appear while the scanning process is in progress.