Sign in to follow this  
Followers 0
snify

FloodFill without direct GDI

4 posts in this topic

Not sure if it goes here or in general help :/

Anyway, I would like to use FloodFill without the GDI or convert at least the DC format to HBITMAP.

Here is what I would like to do:

1. Take a screenshot (_ScreenCapture_Capture)

2. Create a solid brush

3. Select the Object of the HBITMAP from the screenshot

4. FloodFill a certain area with a certain color

5. Save the output back to a file or HBITMAP.

The Problem is that you need a GUI/Handle to do all that. Any other ways to do all this in the background instead in front of the nose of the user?!

Thank you for your help :)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

There is no fill function in GDI+, so I wrote one. :)

Try this:

#include <GDIPlus.au3>

$sRegPath = "HKLM\SOFTWARE\AutoIt v3\AutoIt"
If StringInStr("X64IA64", @OSArch) Then $sRegPath = StringReplace($sRegPath, "SOFTWARE", "SOFTWARE\Wow6432Node")

_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile(RegRead($sRegPath, "InstallDir") & "\Examples\GUI\logo4.gif")

$iColor2Fill = 0xFFFFFFFF
;~ _GDIPlus_FloodFill($hImage, 10, 10, 0xFF000080, 0xFFFFFF00)
_GDIPlus_FloodFill($hImage, 73, 22, $iColor2Fill, 0xFFFFFF00)
_GDIPlus_FloodFill($hImage, 88, 27, $iColor2Fill, 0xFFFFFF00)
_GDIPlus_FloodFill($hImage, 99, 38, $iColor2Fill, 0xFFFFFF00)
_GDIPlus_FloodFill($hImage, 109, 32, $iColor2Fill, 0xFFFFFF00)
_GDIPlus_FloodFill($hImage, 120, 37, $iColor2Fill, 0xFFFFFF00)
_GDIPlus_FloodFill($hImage, 120, 37, $iColor2Fill, 0xFFFFFF00)
_GDIPlus_FloodFill($hImage, 141, 41, $iColor2Fill, 0xFFFFFF00)
_GDIPlus_FloodFill($hImage, 153, 43, $iColor2Fill, 0xFFFFFF00)
_GDIPlus_ImageSaveToFile($hImage, @ScriptDir & "\Filled.png")
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()
ShellExecute(@ScriptDir & "\Filled.png")

Exit

Func _GDIPlus_FloodFillRec(ByRef $hBitmap, $iX, $iY, $iColorOld, $iColorNew) ;coded by UEZ 2013-01-12
    Local Static $iRec = 1
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipBitmapGetPixel", "handle", $hBitmap, "int", $iX, "int", $iY, "uint*", 0)
    If $aResult[4] = "0x" & Hex($iColorOld, 8) Then
        DllCall($ghGDIPDll, "uint", "GdipBitmapSetPixel", "handle", $hBitmap, "int", $iX, "int", $iY, "uint", $iColorNew)
    Else
        Return 0
    EndIf
    Local $iRecLimit = 3899
    $aResult = DllCall($ghGDIPDll, "uint", "GdipGetImageDimension", "handle", $hBitmap, "float*", 0, "float*", 0)
    If ($iX + 1) < $aResult[2] + 1 Then
        $iRec += 1
        If $iRec = $iRecLimit Then Return -1
        _GDIPlus_FloodFillRec($hBitmap, $iX + 1, $iY, $iColorOld, $iColorNew) ;go east
        $iRec -= 1
    EndIf
    If ($iY + 1) < $aResult[3] + 1 Then
        $iRec += 1
        If $iRec = $iRecLimit Then Return -1
        _GDIPlus_FloodFillRec($hBitmap, $iX, $iY + 1, $iColorOld, $iColorNew) ;go south
        $iRec -= 1
    EndIf
    If ($iX - 1) > -1 Then
        $iRec += 1
        If $iRec = $iRecLimit Then Return -1
        _GDIPlus_FloodFillRec($hBitmap, $iX - 1, $iY, $iColorOld, $iColorNew) ;go west
        $iRec -= 1
    EndIf
    If ($iY - 1) > -1 Then
        $iRec += 1
        If $iRec = $iRecLimit Then Return -1
        _GDIPlus_FloodFillRec($hBitmap, $iX, $iY - 1, $iColorOld, $iColorNew) ;go north
        $iRec -= 1
    EndIf
    Return 1
EndFunc   ;==>_GDIPlus_FloodFillRec

It will fill the white color insite the AutoIt logo with color yellow.

Another example:

#include <Memory.au3>
#include <GDIPlus.au3>

_GDIPlus_Startup()
$hImage = _GDIPlus_BMPFromMemory(_ChristianClub())

_GDIPlus_FloodFill($hImage, 200, 200, 0xFFFFFFFF, 0xFF0000FF)
_GDIPlus_ImageSaveToFile($hImage, @ScriptDir & "\Filled.png")
_GDIPlus_BitmapDispose($hImage)
_GDIPlus_Shutdown()
ShellExecute(@ScriptDir & "\Filled.png")

Exit

Func _GDIPlus_FloodFillRec(ByRef $hBitmap, $iX, $iY, $iColorOld, $iColorNew) ;coded by UEZ 2013-01-12
    Local Static $iRec = 1
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipBitmapGetPixel", "handle", $hBitmap, "int", $iX, "int", $iY, "uint*", 0)
    If $aResult[4] = "0x" & Hex($iColorOld, 8) Then
        DllCall($ghGDIPDll, "uint", "GdipBitmapSetPixel", "handle", $hBitmap, "int", $iX, "int", $iY, "uint", $iColorNew)
    Else
        Return 0
    EndIf
    Local $iRecLimit = 3899
    $aResult = DllCall($ghGDIPDll, "uint", "GdipGetImageDimension", "handle", $hBitmap, "float*", 0, "float*", 0)
    If ($iX + 1) < $aResult[2] + 1 Then
        $iRec += 1
        If $iRec = $iRecLimit Then Return -1
        _GDIPlus_FloodFillRec($hBitmap, $iX + 1, $iY, $iColorOld, $iColorNew) ;go east
        $iRec -= 1
    EndIf
    If ($iY + 1) < $aResult[3] + 1 Then
        $iRec += 1
        If $iRec = $iRecLimit Then Return -1
        _GDIPlus_FloodFillRec($hBitmap, $iX, $iY + 1, $iColorOld, $iColorNew) ;go south
        $iRec -= 1
    EndIf
    If ($iX - 1) > -1 Then
        $iRec += 1
        If $iRec = $iRecLimit Then Return -1
        _GDIPlus_FloodFillRec($hBitmap, $iX - 1, $iY, $iColorOld, $iColorNew) ;go west
        $iRec -= 1
    EndIf
    If ($iY - 1) > -1 Then
        $iRec += 1
        If $iRec = $iRecLimit Then Return -1
        _GDIPlus_FloodFillRec($hBitmap, $iX, $iY - 1, $iColorOld, $iColorNew) ;go north
        $iRec -= 1
    EndIf
    Return 1
EndFunc   ;==>_GDIPlus_FloodFillRec

;======================================================================================
; Function Name:         _GDIPlus_BMPFromMemory
; Description:                Loads an image which is saved as a binary string and converts it to a bitmap or hbitmap
;
; Parameters:                $bImage:    the binary string which contains any valid image which is supported by GDI+
; Optional:                     $hHBITMAP:  if false a bitmap will be created, if true a hbitmap will be created
;
; Remark:                       hbitmap format is used generally for GUI internal images, $bitmap is more a GDI+ image format
;                                       Don't forget _GDIPlus_Startup() and _GDIPlus_Shutdown()
;
; Requirement(s):        GDIPlus.au3, Memory.au3 and _WinAPI_BitmapCreateDIBFromBitmap() from WinAPIEx.au3
; Return Value(s):        Success: handle to bitmap (GDI+ bitmap format) or hbitmap (WinAPI bitmap format),
;                                       Error: 0
; Error codes:              1: $bImage is not a binary string
;                                       2: unable to create stream on HGlobal
;                                       3: unable to create bitmap from stream
;
; Author(s):                    UEZ
; Additional Code:        thanks to progandy for the MemGlobalAlloc and tVARIANT lines and
;                                           Yashied for _WinAPI_BitmapCreateDIBFromBitmap() from WinAPIEx.au3
; Version:                      v0.98 Build 2012-08-29 Beta
;=======================================================================================
Func _GDIPlus_BMPFromMemory($bImage, $hHBITMAP = False)
    If Not IsBinary($bImage) Then Return SetError(1, 0, 0)
    Local $aResult
    Local Const $memBitmap = Binary($bImage) ;load image  saved in variable (memory) and convert it to binary
    Local Const $len = BinaryLen($memBitmap) ;get length of image
    Local Const $hData = _MemGlobalAlloc($len, $GMEM_MOVEABLE) ;allocates movable memory  ($GMEM_MOVEABLE = 0x0002)
    Local Const $pData = _MemGlobalLock($hData) ;translate the handle into a pointer
    Local $tMem = DllStructCreate("byte[" & $len & "]", $pData) ;create struct
    DllStructSetData($tMem, 1, $memBitmap) ;fill struct with image data
    _MemGlobalUnlock($hData) ;decrements the lock count  associated with a memory object that was allocated with GMEM_MOVEABLE
    $aResult = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "handle", $pData, "int", True, "ptr*", 0) ;Creates a stream object that uses an HGLOBAL memory handle to store the stream contents
    If @error Then Return SetError(2, 0, 0)
    Local Const $hStream = $aResult[3]
    $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromStream", "ptr", $hStream, "int*", 0) ;Creates a Bitmap object based on an IStream COM interface
    If @error Then Return SetError(3, 0, 0)
    Local Const $hBitmap = $aResult[2]
    Local $tVARIANT = DllStructCreate("word vt;word r1;word r2;word r3;ptr data; ptr")
    DllCall("oleaut32.dll", "long", "DispCallFunc", "ptr", $hStream, "dword", 8 + 8 * @AutoItX64, _
                                           "dword", 4, "dword", 23, "dword", 0, "ptr", 0, "ptr", 0, "ptr", DllStructGetPtr($tVARIANT)) ;release memory from $hStream to avoid memory leak
    $tMem = 0
    $tVARIANT = 0
    If $hHBITMAP Then
        Local Const $hHBmp = _WinAPI_BitmapCreateDIBFromBitmap($hBitmap)
        _GDIPlus_BitmapDispose($hBitmap)
        Return $hHBmp
    EndIf
    Return $hBitmap
EndFunc   ;==>_GDIPlus_BMPFromMemory

Func _WinAPI_BitmapCreateDIBFromBitmap($hBitmap) ;create 32-bit bitmap v5 (alpha channel supported)
    Local $tBIHDR, $aRet, $tData, $pBits, $hResult = 0
    $aRet = DllCall($ghGDIPDll, 'uint', 'GdipGetImageDimension', 'ptr', $hBitmap, 'float*', 0, 'float*', 0)
    If (@error) Or ($aRet[0]) Then Return 0
    $tData = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $aRet[2], $aRet[3], $GDIP_ILMREAD, $GDIP_PXF32ARGB)
    $pBits = DllStructGetData($tData, 'Scan0')
    If Not $pBits Then Return 0
    $tBIHDR = DllStructCreate(    'dword bV5Size;long bV5Width;long bV5Height;word bV5Planes;word bV5BitCount;dword bV5Compression;' & _ ;http://msdn.microsoft.com/en-us/library/windows/desktop/dd183381(v=vs.85).aspx
                                                                'dword bV5SizeImage;long bV5XPelsPerMeter;long bV5YPelsPerMeter;dword bV5ClrUsed;dword bV5ClrImportant;'  & _
                                                                'dword bV5RedMask;dword bV5GreenMask;dword bV5BlueMask;dword bV5AlphaMask;dword bV5CSType;' & _
                                                                'int bV5Endpoints[3];dword bV5GammaRed;dword bV5GammaGreen;dword bV5GammaBlue;dword bV5Intent;' & _
                                                                'dword bV5ProfileData;dword bV5ProfileSize;dword bV5Reserved')
    DllStructSetData($tBIHDR, 'bV5Size', DllStructGetSize($tBIHDR))
    DllStructSetData($tBIHDR, 'bV5Width', $aRet[2])
    DllStructSetData($tBIHDR, 'bV5Height', $aRet[3])
    DllStructSetData($tBIHDR, 'bV5Planes', 1)
    DllStructSetData($tBIHDR, 'bV5BitCount', 32)
    DllStructSetData($tBIHDR, 'bV5Compression', 0) ; $BI_BITFIELDS = 3, $BI_RGB = 0, $BI_RLE8 = 1, $BI_RLE4 = 2, $RGBA = 0x41424752
    DllStructSetData($tBIHDR, 'bV5SizeImage', $aRet[3] * DllStructGetData($tData, 'Stride'))
    DllStructSetData($tBIHDR, 'bV5AlphaMask', 0xFF000000)
    DllStructSetData($tBIHDR, 'bV5RedMask', 0x00FF0000)
    DllStructSetData($tBIHDR, 'bV5GreenMask', 0x0000FF00)
    DllStructSetData($tBIHDR, 'bV5BlueMask', 0x000000FF)
    DllStructSetData($tBIHDR, 'bV5CSType', 2) ; LCS_WINDOWS_COLOR_SPACE = 2
    DllStructSetData($tBIHDR, 'bV5Intent', 4) ; $LCS_GM_IMA
    $hResult = DllCall('gdi32.dll', 'ptr', 'CreateDIBSection', 'hwnd', 0, 'ptr', DllStructGetPtr($tBIHDR), 'uint', 0, 'ptr*', 0, 'ptr', 0, 'dword', 0)
    If (Not @error) And ($hResult[0]) Then
        DllCall('gdi32.dll', 'dword', 'SetBitmapBits', 'ptr', $hResult[0], 'dword', $aRet[2] * $aRet[3] * 4, 'ptr', DllStructGetData($tData, 'Scan0'))
        $hResult = $hResult[0]
    Else
        $hResult = 0
    EndIf
    _GDIPlus_BitmapUnlockBits($hBitmap, $tData)
    $tData = 0
    $tBIHDR = 0
    Return $hResult
EndFunc   ;==>_WinAPI_BitmapCreateDIBFromBitmap

;Code below was generated by: 'File to Base64 String' Code Generator v1.11 Build 2012-10-13

Func _ChristianClub($bSaveBinary = False)
    Local $ChristianClub
    $ChristianClub &= 'R0lGODlh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ALRyuHanxjL2PqNJ3jNzdbNUWeNJYVrKI3dQeM9IBna6rjN3MPdmPPWlajWgJ3cqvgNsyZtYL4ZZyHd0eFMnd697woYzBP9aV+Tsthnyz6U0mMznfyf3cJeVTAUTeWFk5ELHf0JeMoz3G2qsn620n6uRqyo2Jm42JFE4s8V3h8nNWAT62GM6XzurWgj2+EJ7E2FTgk6KD/WjiCS7eLg7jMe7iLS7j8mfcNX40kYvj7sraKb7jculEIv7jAAI0Ejvk1zhhRw7ddazkJa7aTQ7lUS7lU07lVW7lV47lWa7lW87lu1AAADs='
    Local $bString = Binary(_Base64Decode($ChristianClub))
    If $bSaveBinary Then
        Local $hFile = FileOpen(@ScriptDir & "\Europe.gif", 18)
        FileWrite($hFile, $bString)
        FileClose($hFile)
    EndIf
    Return  $bString
EndFunc   ;==>_ChristianClub

Func _Base64Decode($sB64String)
    Local $struct = DllStructCreate("int")
    Local $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", "str", $sB64String, "int", 0, "int", 1, "ptr", 0, "ptr", DllStructGetPtr($struct, 1), "ptr", 0, "ptr", 0)
    If @error Or Not $a_Call[0] Then Return SetError(1, 0, "")
    Local $a = DllStructCreate("byte[" & DllStructGetData($struct, 1) & "]")
    $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", "str", $sB64String, "int", 0, "int", 1, "ptr", DllStructGetPtr($a), "ptr", DllStructGetPtr($struct, 1), "ptr", 0, "ptr", 0)
    If @error Or Not $a_Call[0] Then Return SetError(2, 0, "")
    Return DllStructGetData($a, 1)
EndFunc   ;==>_Base64Decode

I know this is not GDI but GDI+. Maybe it fulfill your needs, too.

Limitation: recursion max. level of 3899 (x86).

Br,

UEZ

Edited by UEZ
1 person likes this

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

This is really good and well made. Thank you so much!

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

There is unfortunately one problem with the code: recursion level limit.

When I find some stressless time I will do the iterativ way to bypass the recursion level limit issue.

Here the iterative way:

#include <GDIPlus.au3>

$sRegPath = "HKLM\SOFTWARE\AutoIt v3\AutoIt"
If StringInStr("X64IA64", @OSArch) Then $sRegPath = StringReplace($sRegPath, "SOFTWARE", "SOFTWARE\Wow6432Node")

_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile(RegRead($sRegPath, "InstallDir") & "\Examples\GUI\logo4.gif")
$iW = _GDIPlus_ImageGetWidth($hImage)
$iH = _GDIPlus_ImageGetHeight($hImage)
$hGUI = GUICreate("Test", $iW, $iH)
GUISetState()
$hGfx = _GDIPlus_GraphicsCreateFromHWND($hGUI)
AdlibRegister("UpdateView", 10)

$iColor2Fill = 0xFFFFFFFF
_GDIPlus_FloodFillIter2($hImage, 0, 0, 0xFF000080, 0xFFFFFF00)
_GDIPlus_ImageSaveToFile($hImage, @ScriptDir & "\Filled.png")
;~ ShellExecute(@ScriptDir & "\Filled.png")
AdlibUnRegister("UpdateView")
ConsoleWrite("Done" & @LF)
Do
Until GUIGetMsg() = -3

_GDIPlus_ImageDispose($hImage)
_GDIPlus_GraphicsDispose($hGfx)
_GDIPlus_Shutdown()
Exit

Func _GDIPlus_FloodFillIter2(ByRef $hBitmap, $iX, $iY, $iColorOld, $iColorNew) ;coded by UEZ 2013-01-13
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipGetImageDimension", "handle", $hBitmap, "float*", 0, "float*", 0)
    Local $iW = $aResult[2], $iH = $aResult[3]
    If BitOR($iX < 0, $iY < 0, $iX > $iW - 1, $iY > $iH - 1) Then Return SetError(1, 0, 0)
    Local $x, $y, $i = 1
    Local $oD = ObjCreate('Scripting.Dictionary')
    $oD.Add($i, $iX & ";" & $iY) ;push
    $i += 1
    While $oD.Count > 0
        $sPoint = $oD.Item($i - 1)
        $oD.Remove($i - 1) ;pop
        $i -= 1
        $x = Int(StringRegExpReplace($sPoint, "(\d+);\d+", "$1"))
        $y = Int(StringRegExpReplace($sPoint, "\d+;(\d+)", "$1"))
        If BitOR($x < 0, $y < 0, $x > $iW - 1, $y > $iH - 1) Then ContinueLoop
        $aResult = DllCall($ghGDIPDll, "uint", "GdipBitmapGetPixel", "handle", $hBitmap, "int", $x, "int", $y, "uint*", 0)
        If $aResult[4] = "0x" & Hex($iColorOld, 8) Then
            DllCall($ghGDIPDll, "uint", "GdipBitmapSetPixel", "handle", $hBitmap, "int", $x, "int", $y, "uint", $iColorNew)
            $oD.Add($i, $x + 1 & ";" & $y) ;push
            $i += 1
            $oD.Add($i, $x & ";" & $y + 1) ;push
            $i += 1
            $oD.Add($i, $x - 1 & ";" & $y) ;push
            $i += 1
            $oD.Add($i, $x & ";" & $y - 1) ;push
            $i += 1
        EndIf
    WEnd
    $oD = 0
    Return 1
EndFunc   ;==>_GDIPlus_FloodFillIter2

Func UpdateView()
    _GDIPlus_GraphicsDrawImage($hGfx, $hImage, 0, 0)
EndFunc

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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  
Followers 0