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

Post your working scripts, libraries and tools
just me
Posts: 7107
Joined: 02 Oct 2013, 08:51
Location: Germany

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

26 Apr 2015, 04:39

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.
Last edited by just me on 06 Mar 2020, 06:13, edited 6 times in total.
vasili111
Posts: 747
Joined: 21 Jan 2014, 02:04
Location: Georgia

Re: WIA - Windows Image Acquisition (Automation Layer)

26 Apr 2015, 15:54

just me
Nice and useful library. Thank you :)
DRAKON-AutoHotkey: Visual programming for AutoHotkey.
just me
Posts: 7107
Joined: 02 Oct 2013, 08:51
Location: Germany

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

27 Apr 2015, 10:56

*Update 1.0.01.00 on 2015-04-27*
Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

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

27 Apr 2015, 14:44

my XP choked here:
Loop, Files, %A_WinDir%\Web\WallPaper\*.jpg, R
:morebeard:
just me
Posts: 7107
Joined: 02 Oct 2013, 08:51
Location: Germany

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

28 Apr 2015, 01:23

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
carno
Posts: 210
Joined: 20 Jun 2014, 16:48

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

28 Apr 2015, 05:01

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
just me
Posts: 7107
Joined: 02 Oct 2013, 08:51
Location: Germany

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

28 Apr 2015, 08:14

The latest version is 1.1.21.03, otherwise ...

Or you might want to put an image file path manually into ImgPath.
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

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

16 May 2015, 15:22

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!
just me
Posts: 7107
Joined: 02 Oct 2013, 08:51
Location: Germany

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

17 May 2015, 00:19

Hi kon,

thanks for your suggestions. Better now? ;)
swagfag
Posts: 3763
Joined: 11 Jan 2017, 17:59

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

07 Nov 2019, 12:10

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?
just me
Posts: 7107
Joined: 02 Oct 2013, 08:51
Location: Germany

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

08 Nov 2019, 11:33

You might want to search for it in the registry (HKCR).

By the way, the function returns an object reference on success.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

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

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.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
boiler
Posts: 5241
Joined: 21 Dec 2014, 02:44

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

08 Nov 2019, 13:34

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.
swagfag
Posts: 3763
Joined: 11 Jan 2017, 17:59

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

08 Nov 2019, 14:12

nevermind, i thought it returned a pointer for some reason
it does work when u test with IsObject
robodesign
Posts: 652
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
GitHub: mariussucan
Location: Romania
Contact:

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

08 Nov 2019, 16:56

Can it acquire scanner images? It's what it suggests, the name....
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
Quick Picto Viewer: GitHub or forum.
AHK GDI+ expanded / compilation library (on GitHub)
My home page.
robodesign
Posts: 652
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
GitHub: mariussucan
Location: Romania
Contact:

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

04 Mar 2020, 07:50

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.
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
Quick Picto Viewer: GitHub or forum.
AHK GDI+ expanded / compilation library (on GitHub)
My home page.
burque505
Posts: 1301
Joined: 22 Jan 2017, 19:37

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

10 Mar 2020, 14:38

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
robodesign
Posts: 652
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
GitHub: mariussucan
Location: Romania
Contact:

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

10 Mar 2020, 18:21

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.
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
Quick Picto Viewer: GitHub or forum.
AHK GDI+ expanded / compilation library (on GitHub)
My home page.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: Bing [Bot], malcev, zhotkey and 130 guests