Skip to content

Instantly share code, notes, and snippets.

@vadimkantorov
Created February 10, 2015 01:02
Show Gist options
  • Save vadimkantorov/755adc946aefb1f1cf87 to your computer and use it in GitHub Desktop.
Save vadimkantorov/755adc946aefb1f1cf87 to your computer and use it in GitHub Desktop.
A PowerShell script to acquire an image from a scanner and to save it in PNG
$deviceManager = new-object -ComObject WIA.DeviceManager
$device = $deviceManager.DeviceInfos.Item(1).Connect()
$wiaFormatPNG = "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}"
foreach ($item in $device.Items) {
$image = $item.Transfer($wiaFormatPNG)
}
if($image.FormatID -ne $wiaFormatPNG)
{
$imageProcess = new-object -ComObject WIA.ImageProcess
$imageProcess.Filters.Add($imageProcess.FilterInfos.Item("Convert").FilterID)
$imageProcess.Filters.Item(1).Properties.Item("FormatID").Value = $wiaFormatPNG
$image = $imageProcess.Apply($image)
}
$fname = ("{0:D03}_" -f $args[0]) + $args[1] + ".png"
$image.SaveFile("$(pwd)/$fname")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment