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

Post your working scripts, libraries and tools
Janusz
Posts: 63
Joined: 18 Dec 2020, 17:47

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

Post by Janusz » 26 Mar 2021, 16:47

Please, where to find gdip_all.ahk?
Thank all of us who have developed so wonderful libraryes. WIA is very imortant Windows object and thanks to WIA library and other special routines available in other discussion forum thread it is even possible to create fully functional document scanner for visually impaired users with only using build in objects libraryes in to windows 10. Windows 10 allready contain very accurate OCR engine. WIA allow to scan images. Sure, there would had to be performed other complex work. Use some object library or other library which is able to store scanned pages in to .tif format, because .tif format is The good format to send The data to OCR engine.
https://www.autohotkey.com/boards/viewtopic.php?t=72674

I will try to experiment with EIA. DId someone of use have implement The feature to set brightness of scanner lamp and contrast before acquiring image? Or unfortunately, WIA related object library does not support this feature?
Janusz
Posts: 63
Joined: 18 Dec 2020, 17:47

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

Post by Janusz » 26 Mar 2021, 17:22

I have found The .ahk library on A separate thread. FOrtunately, included Dropbox link is valid. And I will continue working on document scanner during a weekend days.
robodesign
Posts: 758
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)

Post by robodesign » 26 Mar 2021, 17:27

Janusz wrote:
26 Mar 2021, 16:47
Please, where to find gdip_all.ahk?
Thank all of us who have developed so wonderful libraryes. WIA is very imortant Windows object and thanks to WIA library and other special routines available in other discussion forum thread it is even possible to create fully functional document scanner for visually impaired users with only using build in objects libraryes in to windows 10. Windows 10 allready contain very accurate OCR engine. WIA allow to scan images. Sure, there would had to be performed other complex work. Use some object library or other library which is able to store scanned pages in to .tif format, because .tif format is The good format to send The data to OCR engine.
https://www.autohotkey.com/boards/viewtopic.php?t=72674

I will try to experiment with EIA. DId someone of use have implement The feature to set brightness of scanner lamp and contrast before acquiring image? Or unfortunately, WIA related object library does not support this feature?
Gdip is at the following address.
https://github.com/marius-sucan/AHK-GDIp-Library-Compilation


If you need an image viewer and scanner developed by a person (and for people) with eyesight impairments, you can can try my script... It's in my signature - quick picture viewer. It has specific options to make all panels large and even the texts in the viewport. You can also right-click on almost any control to see the text displayed even larger, for menu items as well.

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.
robodesign
Posts: 758
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)

Post by robodesign » 26 Mar 2021, 17:28

-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
Quick Picto Viewer: GitHub or forum.
AHK GDI+ expanded / compilation library (on GitHub)
My home page.
Janusz
Posts: 63
Joined: 18 Dec 2020, 17:47

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

Post by Janusz » 27 Mar 2021, 06:40

I would like to publicly thankto MR Sucan for his code. I have A very very big plea addressed to him. Do you think, that it would be possible to extend yours code so scanning would begin automatically so GUI dialog of WIA object would not be shown at all?
Here is very useful discussion on Microsoft MSDN network.
https://social.msdn.microsoft.com/Forums/en-US/c90ea2f4-869c-404b-bde7-8161fbaa8e4f/use-wia-scan-dialog-without-preview?forum=vbgeneral
May be, that some parts of visual Basic Net# code could be made possible for autohotkey.
robodesign
Posts: 758
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)

Post by robodesign » 27 Mar 2021, 09:14

Janusz wrote:
27 Mar 2021, 06:40
I would like to publicly thankto MR Sucan for his code. I have A very very big plea addressed to him. Do you think, that it would be possible to extend yours code so scanning would begin automatically so GUI dialog of WIA object would not be shown at all?
Here is very useful discussion on Microsoft MSDN network.
https://social.msdn.microsoft.com/Forums/en-US/c90ea2f4-869c-404b-bde7-8161fbaa8e4f/use-wia-scan-dialog-without-preview?forum=vbgeneral
May be, that some parts of visual Basic Net# code could be made possible for autohotkey.
The suggestion is out of the scope of the image viewer. I don't intend to skip the standard scanner /device options dialogs

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.
Janusz
Posts: 63
Joined: 18 Dec 2020, 17:47

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

Post by Janusz » 28 Mar 2021, 03:50

I would like to share A very useful VBA macro with you, because this code can be very useful for all of us, who would like to control WIA object so WIA would never display its dialog. VBA macro contain code and object functions and its values, which allow to initiate scanning with predefined parameters of scanning.

Who of us would try to adapt The code for initiating scanning without dialog window? Do you think, that it is also necessary in Autohotkey, or VBA is very specific and it contain some hydden magic, which can not be reach from Autohotkey perspective? Code is very well commented in The following thread.

https://www.slipstick.com/developer/code-samples/vba-scan-email/
Janusz
Posts: 63
Joined: 18 Dec 2020, 17:47

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

Post by Janusz » 28 Mar 2021, 04:36

If you are having Microsoft Net framework preinstalled, I have found other very useful solution. Command line tool written in VB.net with source code commented. It is possible to control scanning device by only using command line option. Read licensing condition of This command line very carefully before you will include this simple utility as A part of yours projects written in Autohotkey.

https://github.com/nagimov/wia-cmd-scanner/releases/tag/0.2.2
Visual Basic Net source can serve also as AN inspiration for Autohotkey coding. Or you can even try to control This app from script. But it would not be so easy to automatically control some console based app. you would need to control, if app creates files in The folder or by auto detecting some running process, ETC. Or you can use The Visual Basic code as A inspiration for controlling WEIA object library. WIA can be even installed for WIndows XP SP1 and higher.
just me
Posts: 7915
Joined: 02 Oct 2013, 08:51
Location: Germany

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

Post by just me » 28 Mar 2021, 06:57

WIA.DeviceManager

Code: Select all

; ======================================================================================================================
; WIA -> https://docs.microsoft.com/en-us/windows/win32/wia/-wia-startpage
;     -> https://docs.microsoft.com/en-us/previous-versions/windows/desktop/wiaaut/-wiaaut-startpage
; ======================================================================================================================
#NoEnv
FmtIDs := {"{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}": "BMP", "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}": "PNG"
         , "{B96B3CB0-0728-11D3-9D7B-0000F81EF32E}": "GIF", "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}": "JPEG"
         , "{B96B3CB1-0728-11D3-9D7B-0000F81EF32E}": "TIFF"}
DevTypes := {0: "UnspecifiedDeviceType", 1: "ScannerDeviceType", 2: "CameraDeviceType", 3: "VideoDeviceType"}
; ----------------------------------------------------------------------------------------------------------------------
DevManager := ComObjCreate("WIA.Devicemanager")
DevCount := DevManager.DeviceInfos.Count
I := 0
Device := 0
While (I < DevCount) {
   DevInfo := DevManager.DeviceInfos(++I)
   If (DevInfo.Type = 1) { ; it's a scanner
      Device := DevInfo.Connect
      Break
   }
}
If !(Device) {
   MsgBox, Could not find a scanner device!
   ExitApp
}
Item := Device.Items(1)
DevName := Device.Properties("Name").Value
Gui, Margin, 10, 10
Gui, Add, ListView, xm w800 r30 vLV, Name (ID)|Value
Gui, Add, Button, xm w200 gDeviceProps vDP, Show Device Properties
Gui, Add, Button, x+400 yp w200 gItemProps vIP, Show Item Properties
Gui, Show, , Device %DevName%
Return
; ======================================================================================================================
DeviceProps:
   GuiControl, Disable, DP
   GuiControl, Enable, IP
   GuiControl, -Redraw, LV
   LV_Delete()
   For P In Device.Properties {
      N := p.Name . " (" . P.PropertyID . ")"
      If P.IsVector
         V := "[vector of data]"
      Else
         If (P.Type = 16) ; StringPropertyType
            V := """" . P.Value . """"
         Else
            V := P.Value
      LV_Add("", N, V)
   }
   LV_ModifyCol()
   GuiControl, +Redraw, LV
Return
; ======================================================================================================================
ItemProps:
   GuiControl, Disable, IP
   GuiControl, Enable, DP
   GuiControl, -Redraw, LV
   LV_Delete()
   For P In Item.Properties {
      N := P.Name . " (" . P.PropertyID . ")"
      If P.IsVector
         V := "[vector of data]"
      Else
         If (P.Type = 16) ; StringPropertyType
            V := """" . P.Value . """"
         Else
            V := P.Value
      LV_Add("", N, V)
   }
   LV_ModifyCol()
   GuiControl, +Redraw, LV
Return
; ======================================================================================================================
GuiClose:
ExitApp
Janusz
Posts: 63
Joined: 18 Dec 2020, 17:47

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

Post by Janusz » 28 Mar 2021, 07:38

Dear just me. I AM sending you a nice greetings to Germany. I have just tried yours WIA device manager and it is really excellent app. And fully accessible and contain all available scanner properties. Very good example how to use WIA. Very well done.
And thank you that you have sent code directly to yours forum post. Data will never disappear like if somebody uses Dropbox download links. Thank you.
Janusz
Posts: 63
Joined: 18 Dec 2020, 17:47

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

Post by Janusz » 29 Mar 2021, 14:57

I have found out what is The problem. There is issue that I do not know, if Autohotkey have An equivalent command to Width VBA command. Sure, Autohotkey is not VBA. It is new language and uses other commands. But COm work perfectly also from Autohotkey. But I understand, that it is not useful topic for forum majority, automatisation of scanning, because WIA dialog can be accessed by build in hot keys such as ALT+S for scanning. And may be, that it would be even possible to create macro to send hotkey in The right time. It is also true, that professional companyes have seeling OCR apps which are designed to automatically WIA dialog so I will stop bothering all of us with this. Thank you for yours time and for yours big patience.
Janusz
Posts: 63
Joined: 18 Dec 2020, 17:47

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

Post by Janusz » 12 Apr 2021, 14:54

I have finally found out what we need. Find The way how to access WIA object properties and how to assign value of every properties.
.Properties("6151").Value = 300
Is there An way how to use Autohotkey for assigning object properties some value? Or it would be necessary to directly call oleacc.dll with some trick?
Because many objects have not only their methods, but also properties. And every object property can have various values. BUt The question is, if is it possible to change those values in Autohotkey for now.

The following WIA property is also important.
' .Properties("6146").Value = 1 '4 is Black-white,gray is 2, color 1 (Color Intent)
'
Janusz
Posts: 63
Joined: 18 Dec 2020, 17:47

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

Post by Janusz » 13 Apr 2021, 04:37

May be, that I have found very useful forum thread about this problematic. It would even allow Me to finally avoid WIA scanner dialog to appear. If VBA language build in to Word can do that, why Autohotkey would not be also capable to do that?
I must finish my heavy software fight.
just me
Posts: 7915
Joined: 02 Oct 2013, 08:51
Location: Germany

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

Post by just me » 13 Apr 2021, 05:40

Neither VB(A) nor AHK require the use of a With statement. Instead of

Code: Select all

With Scanner.Items(1)
   .Properties(Key).Value = Value
End With
you can use something like

Code: Select all

Scanner.Items(1).Properties(Key).Value := Value
or

Code: Select all

Item := Scanner.Items(1)
Item(Key).Value := Value
Janusz
Posts: 63
Joined: 18 Dec 2020, 17:47

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

Post by Janusz » 15 Apr 2021, 08:22

Thank you very much for yours hand for help, which you have given to Me. The main reason why I do not want to give it up with automated scanning is The fact, that small and efficient executables, which are capable to make automated scanning are not very common today. Big installation bundles with The proprietary OCR software are in many cases not very needed, if somebody do not want to do his best to create .doc file with original page layout with original font as in A book, font syze, ETC. I have good experience with build in to Windows 10 Windows media OCR dlls. So I will do my best to combine posts in Autohotkey forum with some good answers to create fully automated scanning app not only for visually impaired users. I will be using standard Autohotkey editable field to add append new recognized pages by using WIndows Media OCR APi. Sure. I Am aware, that WIndows media OCR API is not Abbyy FIne reader or Microsoft document Imaging build in OCR engine. So I can not get original page layout including font names, syzes, etc. I can only get Ascii text output. BUt this is enough for simple scanning. For better results, it is necessary to use and buy professional OCR apps on The market. Thank you for yours help. I will test it.
Janusz
Posts: 63
Joined: 18 Dec 2020, 17:47

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

Post by Janusz » 15 Apr 2021, 08:57

I have also observed very important fact when analysing VBA
Author do not use Acquire but
Set wiaImg = wiaScanner.Items(1).Transfer(wiaFormatTIFF)

I will be hoping, that there will not be some hydden issue with Autohotkey. BUt I thing, that no. Autohotkey have big capabilities and programmers logic is The main limitation factor of success.
BoBo
Posts: 4609
Joined: 13 May 2014, 17:15

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

Post by BoBo » 15 Apr 2021, 10:49

@Janusz
I must finish my heavy software fight.
I'm fully with you on this - IMHO your best chance, checking out for command-line applications (open source and sometimes Linux related applications have been compiled to Windows binaries too, or (best case) if its source is available you can compile it on your own!). Good luck and keep up the fight! Venceremos :lol:
just me
Posts: 7915
Joined: 02 Oct 2013, 08:51
Location: Germany

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

Post by just me » 17 Apr 2021, 06:07

Hi @Janusz,

this is my last answer related to your questions here. If you need further help, open a new thread in 'Ask For Help' , please. Maybe others are more interested in this topic.

Code: Select all

; ======================================================================================================================
; WIA -> https://docs.microsoft.com/en-us/windows/win32/wia/-wia-startpage
;     -> https://docs.microsoft.com/en-us/previous-versions/windows/desktop/wiaaut/-wiaaut-startpage
; ======================================================================================================================
#NoEnv
FormatID := {BMP: "{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}", PNG: "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}"
           , GIF: "{B96B3CB0-0728-11D3-9D7B-0000F81EF32E}", JPG: "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}"
           , TIF: "{B96B3CB1-0728-11D3-9D7B-0000F81EF32E}"}
DevTypes := {0: "UnspecifiedDeviceType"
           , 1: "ScannerDeviceType"
           , 2: "CameraDeviceType"
           , 3: "VideoDeviceType"}
ImgTypes := {0: "WIA_INTENT_NONE"
           , 1: "WIA_INTENT_IMAGE_TYPE_COLOR"
           , 2: "WIA_INTENT_IMAGE_TYPE_GRAYSCALE"
           , 4: "WIA_INTENT_IMAGE_TYPE_TEXT"}
WIA_IPS_PAGE_SIZE := "3097" ; Page Size
WIA_PAGE_A4     := 0 ; 8267 x 11692
WIA_PAGE_LETTER := 1 ; 8500 x 11000
WIA_PAGE_CUSTOM := 2 ; (current extent settings)
WIA_IPS_CUR_INTENT := "6146" ; Current Intent
WIA_INTENT_NONE                 := 0x00000000
WIA_INTENT_IMAGE_TYPE_COLOR     := 0x00000001 ; RGB
WIA_INTENT_IMAGE_TYPE_GRAYSCALE := 0x00000002 ; grayscale
WIA_INTENT_IMAGE_TYPE_TEXT      := 0x00000004 ; black & white
WIA_INTENT_MINIMIZE_SIZE        := 0x00010000
WIA_INTENT_MAXIMIZE_QUALITY     := 0x00020000
WIA_INTENT_BEST_PREVIEW         := 0x00040000
; ----------------------------------------------------------------------------------------------------------------------
; Image output format
FileExt := ""              ; BMP, GIF, JPG, PNG, TIF
; Device name, if required
DeviceName := ""
; Some device and image properties you may set
DevProps := {}
DevProps["3097"] := ""     ; page size (e.g. 0 = A4, 1 = letter, 2 = custom (current extend settings)
ImgProps := {}
ImgProps["3097"] := ""     ; page size (e.g. 0 = A4, 1 = letter, 2 = custom (current extend settings)
ImgProps["6146"] := 1      ; 1 = RGB color, 2 = grayscale, 4 = black & white
ImgProps["6147"] := ""     ; horizontal resolution (DPI)
ImgProps["6148"] := ""     ; vertical resolution (DPI)
ImgProps["6149"] := ""     ; horizontal start position in pixels
ImgProps["6150"] := ""     ; vertical start position in pixels
ImgProps["6151"] := ""     ; horizontal extend (width) in pixels
ImgProps["6152"] := ""     ; vertical extend (height) in pixels
; ----------------------------------------------------------------------------------------------------------------------
; Check the output format
If (FileExt = "")
   FileExt := "BMP"
If !FormatID.Haskey(FileExt) {
   MsgBox, 36, Scan, % "Output format " . FileExt . " is not supported!`n`n"
                     . "Supported formats are  BMP, GIF, JPG, PNG, TIF.`n"
                     . "The image will be scanned as BMP.`n`n"
                     . "Do you want to continue?"
   IfMsgBox, Yes
      FileExt := "BMP"
   Else
      ExitApp
}
; ----------------------------------------------------------------------------------------------------------------------
DevManager := ComObjCreate("WIA.Devicemanager")
DevCount := DevManager.DeviceInfos.Count
I := 0
Device := 0
While (I < DevCount) {
   DevInfo := DevManager.DeviceInfos(++I)
   If (DevInfo.Type = 1) { ; it's a scanner
      If (DeviceName = "") || (DeviceName = DevInfo.Properties("Name").Value) {
         Device := DevInfo.Connect
         Break
      }
   }
}
If !(Device) {
   MsgBox, Could not find a scanner device!
   ExitApp
}
Name := Device.Properties("Name").Value
Item := Device.Items(1)
; ----------------------------------------------------------------------------------------------------------------------
; Set the properties
For Prop, Value In DevProps
   If (Value <> "")
      Device.Properties(Format("{:04}", Prop)).Value := Value
For Prop, Value In ImgProps
   If (Value <> "")
      Item.Properties(Format("{:04}", Prop)).Value := Value
; Item.Properties("3097").Value := 100 ; A4
Image := Item.Transfer("{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}") ; scan as BMP
; MsgBox, % Image.FormatID
PicObj := WIA_GetImageBitmap(Image)
HBM := PicObj.Handle
Gui, Margin, 10, 10
Gui, Add, Pic, w600 h-1 vPic, HBITMAP:%HBM%
GuiControlGet, Pic, Pos
Gui, Show, , Device %DevName% (%PicW%*%PicH%)
Return
; ======================================================================================================================
; Retrieves the bitmap data of the image.
; Return values:
;     A new Picture object on success, otherwise false.
; Note:
;     To retrieve the HBITMAP handle for the returned object use object.Handle
; ======================================================================================================================
WIA_GetImageBitmap(ImgObj) {
   ; To retrieve the HBITMAP handle for the returned object use object.Handle
   Return (ComObjType(ImgObj, "Name") = "IImageFile") ? ImgObj.Filedata.Picture : False
}
; ======================================================================================================================
GuiClose:
ExitApp
Janusz
Posts: 63
Joined: 18 Dec 2020, 17:47

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

Post by Janusz » 17 Apr 2021, 11:40

Dear Just Me, you are belong among elite Autohotkey programmers. Thank you very much and for yours excellent and professionally prepared code. I will listen yours good advice and I AM very sorry again that I have been intruded here for so long time. Very well done and thank you again.
Post Reply

Return to “Scripts and Functions”