Jump to content
Sign in to follow this  

Bitmap to autoit array

Recommended Posts

I just used Simucal's extprop.au3

and Larry's user32.dll and gdi32.dll exploiting code for finding the colour of a pixel here

#include <ExtProp.au3>


HotKeySet("{ESC}", "Terminate")
Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

;-get last pixels
$imgwidth = StringTrimRight(_GetExtProperty($szPicFile,27),7)-1
$imgheight = StringTrimRight(_GetExtProperty($szPicFile,28),7)-1
$nofpixels = ($imgwidth+1) * ($imgheight+1)

;-initialise Array
Global $imgarray[$imgwidth+1][$imgheight+1]

;-open image
Const $LR_LOADFROMFILE = 0x0010

Dim $hInst, $hBmp, $hMemDC, $hwnd

$hwnd = WinGetHandle("qqqqqq")

$hInst = DllCall("user32.dll","int","GetWindowLong","hWnd",$hwnd, "int",$GWL_HINSTANCE)
$hInst = $hInst[0]

$hBmp = DllCall("user32.dll","hwnd","LoadImage","hwnd",$hInst,"str",$szPicFile,"int",$IMAGE_BITMAP, _
$hBmp = $hBmp[0]

$hMemDC = DllCall("gdi32.dll", "int", "CreateCompatibleDC", "int", 0)
$hMemDC = $hMemDC[0]

DllCall("gdi32.dll", "hwnd", "SelectObject", "int", $hMemDC, "hwnd", $hBmp)

;-get pixels and populate array
ProgressOn("Progress Meter", "Copying Pixels into array") ; start progress bar
For  $y = 0 To Round($imgheight) Step 1
    For  $x = 0 To Round($imgwidth) Step 1
        ;get pixel colour
        $ret = DLLCall("gdi32.dll","int","GetPixel","int",$hMemDC,"int",$x,"int",$y) ;x and y of pixel
        $ret = Hex( $ret[0], 6)
        $ret = StringRight($ret,2) & StringMid($ret,3,2) & StringLeft($ret,2)
        ;stick it in the array
        $imgarray[$x][$y] = $ret

        ProgressSet(   ((($x+1)+($y*$imgwidth))/$nofpixels) * 100,Round((($x+1)+($y*$imgwidth))/1000) & " of " & Round($nofpixels/1000) & " thousands")

ProgressSet(100 , "Done")

;-close image
DllCall("gdi32.dll", "int", "DeleteDC", "hwnd", $hMemDC)
DllCall("gdi32.dll", "int", "DeleteObject", "hwnd", $hBmp)

Now, this is all very nice, and raw image processing can be done, and then the stuff can even be written back to BMP with evilertoaster's BMP library from this post

The problem however, is that both the solution i hacked and the one evilertoaster proposed are very slow.

Mine takes minutes to load very large files into memory on an A64, and i think the same goes for evilertoaster's code.

Is it maybe possible to use the BitBlt function in gdi32.dll to copy the whole image and then access it directly from memory by autoit, and maybe then also write it back to file in the same way. I think this may open new possibilities for doing image processing with autoit.

Share this post

Link to post
Share on other sites

If I'm not mistaken, Larry did use BitBlt for the new pixel Functions in beta (can't remember which one), but the current ones I'm fairly sure are using it.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post

Link to post
Share on other sites

Larry did use BitBlt for the new pixel Functions in beta

I think he knows how to do this sort of stuff, and if I was clever enough i could figure it out from his other work. The problem is that the stuff that has been done is geared towards loading and manipulating screen shots rather than image files, which is what i am trying to do


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...