windows 7 x64 - Scan automation with PowerShell and WIA - How to set PNG as image type -
what have: i'm using powershell 2.0 , wia scan , save image flatbed scanner. goal avoid dialogs, single click. code simple, short , works.
$devicemanager = new-object -comobject wia.devicemanager $device = $devicemanager.deviceinfos.item(1).connect() foreach ($item in $device.items) { $image = $item.transfer() } $image.savefile("d:\scan.$($image.fileextension)") problem: method above produces bmp files. wanted png files instead.
i saw c# code uses wia method user able pass arguments scan dialog png file format
now wonder if , how it's possible achieve same powershell
i found of code here
- http://deletethis.net/dave/?uri=http%3a%2f%2fcerealnumber.livejournal.com%2f47638.html
- http://ardalis.com/powershell-control-over-nikon-d3000-camera
- http://msdn.microsoft.com/en-us/library/windows/desktop/ms630806(v=vs.85).aspx
ps: in case solution involves 'take picture' command (wiacommandtakepicture). unfortunalty canoscan lide 210 doesn't support command
you should pass formatid string argument transfer method. list of available formats available in msdn
however, there's catch. explained here, transfer method doesn't have observe requested format, , output must converted manually in case. converting msdn's vb example powershell (works on machine scanner):
$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) } $image.savefile("c:/my_full_path/test.png")
Comments
Post a Comment