【发布时间】:2018-09-17 05:16:44
【问题描述】:
所以我使用脚本来自动扫描,一切都很好,除了我的扫描仪总是使用平板进行扫描,而且我似乎无法将来源更改为 Feeder。这是我正在使用的代码
# Create object to access the scanner
$deviceManager = new-object -ComObject WIA.DeviceManager
$device = $deviceManager.DeviceInfos.Item(1).Connect()
# Create object to access the scanned image later
$imageProcess = new-object -ComObject WIA.ImageProcess
# Store file format GUID strings
$wiaFormatBMP = "{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}"
$wiaFormatPNG = "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}"
$wiaFormatGIF = "{B96B3CB0-0728-11D3-9D7B-0000F81EF32E}"
$wiaFormatJPEG = "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}"
$wiaFormatTIFF = "{B96B3CB1-0728-11D3-9D7B-0000F81EF32E}"
# Scan the image from scanner as BMP
foreach ($item in $device.Items) {
$image = $item.Transfer()
}
# set type to JPEG and quality/compression level
$imageProcess.Filters.Add($imageProcess.FilterInfos.Item("Convert").FilterID)
$imageProcess.Filters.Item(1).Properties.Item("FormatID").Value = $wiaFormatJPEG
$imageProcess.Filters.Item(1).Properties.Item("Quality").Value = 5
$image = $imageProcess.Apply($image)
# Build filepath from desktop path and filename 'Scan 0'
$filename = "$([Environment]::GetFolderPath("Desktop"))\Scan {0}.jpg"
# If a file named 'Scan 0' already exists, increment the index as long as needed
$index = 0
while (test-path ($filename -f $index)) {[void](++$index)}
$filename = $filename -f $index
# Save image to 'C:\Users\<username>\Desktop\Scan {x}'
$image.SaveFile($filename)
# Show image
& $filename
我只需要更改扫描仪来源,然后保存所有图像。
【问题讨论】:
-
你在哪里分配给
$device,你怎么知道你已经选择了预期的设备? -
其实我没有。但它似乎选择了预期的扫描仪。只有扫描仪的来源是平板,我需要将其更改为 Feeder
标签: powershell wia