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

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

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -