I am making updates to an old image processing app I wrote back when I first got hired on. One request that I have received is to have a "Scan" button on the app so that images can be both scanned and processed without having to open the Epson Scan Manager or push the button (some of the imaging techs have difficulty reaching their scan button from their seats). I have hacked something together in powershell that does the job and can be easily linked to a button in the python app, but I can't select a value for DPI. Resolution matters for these scans, both for customer facing and programmatic reasons, and they have to be at least 300 DPI, but they always save at a much lower resolution and I can't seem to figure out how to get in and alter the WIA settings for the scanner. I can control the compression once the file is saved but I can't control the resolution the scanner uses when it actually scans the picture. I have located this resource but don't know how to actually implement the changing of these settings. We only work with jpegs and these scanners are only used to scan products, with no filters or masks applied, so it should be pretty simple, but I just need to get this DPI thing figured out. This is what I have so far:
Set-ExecutionPolicy RemoteSigned
$deviceManager = new-object -ComObject WIA.DeviceManager
$device = $deviceManager.DeviceInfos.Item(1).Connect()
$imageProcess = new-object -ComObject WIA.ImageProcess
$wiaFormatJPEG = "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}"
foreach ($item in $device.Items) {
$image = $item.Transfer()
}
$Basepath = Join-Path -Path "C:\Users" -ChildPath $env:username
$NewPath = Join-Path -Path $BasePath -ChildPath "Pictures\My Scans\scan daemon"
$filename = Join-Path -Path $NewPath -ChildPath "Scan {0}.jpg"
$index = 0
while (test-path ($filename -f $index)) {[void](++$index)}
$filename = $filename -f $index
$image.SaveFile($filename)
I can get the scan and save the file, but it always gets saved in low res. This is a problem both because our customers want to see high res images and because my image processing app is expecting images of a certain size, and so won't even work correctly on these images if we were willing to use them. I feel like this should be pretty simple, possibly even a single line of code, but I'm not super familiar with Windows or powershell and am currently at a loss concerning what that line of code is or how to find it.
essentially I just want a way to do this:
SetWIAProperty(scannnerItem.Properties, WIA_HORIZONTAL_SCAN_RESOLUTION_DPI, 300);
SetWIAProperty(scannnerItem.Properties, WIA_VERTICAL_SCAN_RESOLUTION_DPI, 300);
in powershell. No matter where I look I can't seem to find a syntax guide for running .net commands in powershell that don't just deal with basic networking.