Page 1 of 3

WIA - Windows Image Acquisition (1.0.02.00 - 2015-05-03)

Posted: 26 Apr 2015, 04:39
by just me
After reading this thread, the linked script by maestrith, the COM example by sinkfaze, and the MSDN docs about the Windows Image Acquisition Automation Layer i found that the ImageFile object combined with ImageProcess object provide a set of easy-to-use methods to manipulate images. I didn't find other threads about this topic in both forums. So I wrote this little WIA lib. All functions won't overwrite passed objects. Also, the lib doesn't support multiple frames as yet, but I think it could be added.
Change History:
Public Function List:
I don't know whether all functions will work properly on Win XP because I cannot test here.
Lib WIA.ahk:
WIASample.ahk:
WIASample_Create.ahk:
WIAFilters.ahk:
This script will show the description of the available filters and their parameters.
Other examples:
License: The Unlicense

Update on 2020-03-06: @robodesign added a WIA_AcquireImage() function.

Update on 2021-03-27: You'll find a link to an extended version of the lib modified by @robodesign here.

Re: WIA - Windows Image Acquisition (Automation Layer)

Posted: 26 Apr 2015, 15:29
by guest3456
awesome nice work

Re: WIA - Windows Image Acquisition (Automation Layer)

Posted: 26 Apr 2015, 15:54
by vasili111
just me
Nice and useful library. Thank you :)

Re: WIA - Windows Image Acquisition (2015-04-27)

Posted: 27 Apr 2015, 10:56
by just me
*Update 1.0.01.00 on 2015-04-27*

Re: WIA - Windows Image Acquisition (2015-04-27)

Posted: 27 Apr 2015, 14:44
by Guest10
my XP choked here:
Loop, Files, %A_WinDir%\Web\WallPaper\*.jpg, R
:morebeard:

Re: WIA - Windows Image Acquisition (2015-04-27)

Posted: 28 Apr 2015, 01:23
by just me
This line is part of the sample script and not included in one of the WIA functions. Do you use the latest AHK version? Otherwise you might replace the line with

Code: Select all

Loop, %A_WinDir%\Web\WallPaper\*.jpg, 0, 1

Re: WIA - Windows Image Acquisition (2015-04-27)

Posted: 28 Apr 2015, 05:01
by carno
I have a similar issue and I use the following version:
AHK Version: 1.1.19.01
Unicode: Yes (32-bit)
Operating System: WIN_XP
Admin Rights: Yes

Re: WIA - Windows Image Acquisition (2015-04-27)

Posted: 28 Apr 2015, 08:14
by just me
The latest version is 1.1.21.03, otherwise ...

Or you might want to put an image file path manually into ImgPath.

Re: WIA - Windows Image Acquisition (1.0.02.00 - 2015-05-03)

Posted: 16 May 2015, 15:22
by kon
Hi just me,

Congratulations on making an awesome lib!

It took me a while of looking through the msdn before I figured out that your example, WIAFilters.ahk, was the best way to see the filters documentation. It might be useful to note this more prominently so other users look there first.

I appreciate your example here. Maybe you could start a collection of examples or links to examples, similar to what tic did for the Gdip tutorials? I think a collection of useful examples in one place would be good. :)

Thanks again!

Re: WIA - Windows Image Acquisition (1.0.02.00 - 2015-05-03)

Posted: 17 May 2015, 00:19
by just me
Hi kon,

thanks for your suggestions. Better now? ;)

Re: WIA - Windows Image Acquisition (1.0.02.00 - 2015-05-03)

Posted: 18 May 2015, 12:46
by kon
:thumbup: Thanks

Re: WIA - Windows Image Acquisition (1.0.02.00 - 2015-05-03)

Posted: 07 Nov 2019, 12:10
by swagfag

Code: Select all

MsgBox % WIA_LoadImage("C:\img.png")

WIA_LoadImage(ImgPath) {
   ImgObj := ComObjCreate("WIA.ImageFile")
   ComObjError(0)
   ImgObj.LoadFile(ImgPath)
   ComObjError(1)
   Return A_LastError ? False : ImgObj
}
returns blank(win10 x64, ahk 1.1.31.1 x64)
is this COM component deleted in windows 10?

Re: WIA - Windows Image Acquisition (1.0.02.00 - 2015-05-03)

Posted: 08 Nov 2019, 11:33
by just me
You might want to search for it in the registry (HKCR).

By the way, the function returns an object reference on success.

Re: WIA - Windows Image Acquisition (1.0.02.00 - 2015-05-03)

Posted: 08 Nov 2019, 12:25
by jeeswg
I have a section, 'COM OBJECT: IMAGES (WIA)', here:

jeeswg's objects tutorial - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=29232

One link has install advice, if you need to install it.

Re: WIA - Windows Image Acquisition (1.0.02.00 - 2015-05-03)

Posted: 08 Nov 2019, 13:34
by boiler
jeeswg wrote:
08 Nov 2019, 12:25
I have a section, 'COM OBJECT: IMAGES (WIA)', here:

jeeswg's objects tutorial - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=29232

One link has install advice, if you need to install it.
There's good advice in the two posts after yours in the thread you linked that would be worth revisiting.

Re: WIA - Windows Image Acquisition (1.0.02.00 - 2015-05-03)

Posted: 08 Nov 2019, 14:12
by swagfag
nevermind, i thought it returned a pointer for some reason
it does work when u test with IsObject

Re: WIA - Windows Image Acquisition (1.0.02.00 - 2015-05-03)

Posted: 08 Nov 2019, 16:56
by robodesign
Can it acquire scanner images? It's what it suggests, the name....

Re: WIA - Windows Image Acquisition (1.0.02.00 - 2015-05-03)

Posted: 04 Mar 2020, 07:50
by robodesign
I managed to implement a working function, for acquiring images from scanners and other devices.

I only tested it with one scanner.

Code: Select all

#include wia.ahk
#include gdip_all.ahk

WIA_AcquireImage() {
   ; returns on success a GDI+ bitmap handle

   wiaDlg := ComObjCreate("WIA.CommonDialog")
   wiaImg := ComObjCreate("WIA.ImageFile")

   dev := wiaDlg.ShowSelectDevice(0, 1)
   If !dev.DeviceID
      Return False

   wiaimg := wiaDlg.ShowAcquireImage(dev.Type)
   PicObj := WIA_GetImageBitmap(wiaImg)
   If (PicObj.Handle)
   {
      pBitmap := Gdip_CreateBitmapFromHBITMAP(PicObj.Handle)
      DeleteObject(PicObj.Handle)
   }

   If StrLen(pBitmap)>3
      Return pBitmap
   Else
      Return False
}
Best regards, Marius.

Re: WIA - Windows Image Acquisition (1.0.02.00 - 2015-05-03)

Posted: 10 Mar 2020, 14:38
by burque505
Hi Marius, nice one!
Here's a little mod with a file selection dialog. Needs work, but works just fine for my purposes so far. At the moment all I wanted to do was not leave AHK to grab a single-page scan. Works with a Canano MF-4360 USB and an Epson ES-500W wireless so far.

To do (I know, when pigs fly ... ;)):
*Multipage
*Image type selection
*Page size selection
*Image scaling
*Convert to PDF
*Add to Excel (scaled)
*Make it look like it was coded by a human
*And so on ...

Code: Select all

#include wia.ahk
#include <GDIP_All>

FileSelectFile, filename, s16, %A_ScriptDir%\default.bmp, Select a BMP to save, Bitmap Files (*.bmp)
SplitPath, filename, OutFileName, , OutExtension, OutNameNoExt
If OutExtension <> ".bmp"
   filename := OutNameNoExt . ".bmp"
else
   filename := filename

WIA_AcquireImage(filename)

Gui, Add, Pic, x0 y0 w695 h900 +0x4E, %filename%
Gui, Show, Autosize, Scanned

return
ExitApp
return

WIA_AcquireImage(filename:="default.bmp") {
   ; returns on success a GDI+ bitmap handle

   wiaDlg := ComObjCreate("WIA.CommonDialog")
   wiaImg := ComObjCreate("WIA.ImageFile")

   wiaimg := wiaDlg.ShowAcquireImage()
   wiaimg.SaveFile(filename)
   PicObj := WIA_GetImageBitmap(wiaImg)
   If (PicObj.Handle)
   {
      pBitmap := Gdip_CreateBitmapFromHBITMAP(PicObj.Handle)
      DeleteObject(PicObj.Handle)
   }

   If StrLen(pBitmap)>3
      Return pBitmap
   Else
      Return False
}

GuiClose:
!Esc::
ExitApp
Regards,
burque505

Re: WIA - Windows Image Acquisition (1.0.02.00 - 2015-05-03)

Posted: 10 Mar 2020, 18:21
by robodesign
Hey, that's nice!

Glad to hear it's working well.

The function I posted is part of my new "quick picture viewer" version I'm working on. It will also have a complete toolbox for image editing and many optimisations, speed improvements... And multithreading and, and.....

Best regards, Marius.