Sign in to follow this  
Followers 0
Mikeman27294

Changing image hue

5 posts in this topic

#1 ·  Posted (edited)

Hey everyone.

I want to add a theming engine to a program of mine, so that there is multiple hues, ie red, green, orange, blue and so on. I also want to be able to change the brightness of the background, ie you can choose between a range oflight greys through to dark greys.

I have searched the forum and came across this:

#include<Array.au3>

#include<Color.au3>

#include<GUIConstantsEx.au3>

GUICreate("",360,350)
$gra = GUICtrlCreateGraphic(0,0,360,20)
GUISetState()
$Color = 0xFFff00
GUISetBkColor($Color)
ConsoleWrite("Color: 0x" & Hex($Color, 6) & @CRLF)
ConsoleWrite("Saturation: " & _Color_GetSaturation($Color) & " %" & @CRLF)
ConsoleWrite("Brightness: " & _Color_GetBrightness($Color) & " %" & @CRLF)
ConsoleWrite("Hue: " & _Color_GetHue($Color) & " º" & @CRLF)
Sleep(1000)
ConsoleWrite("Complementary color: " & _Color_FindComplementary($Color) & @CRLF & @CRLF)
$i = 0
While $i < 2
    $i += 1
    GUISetBkColor(_Color_FindComplementary($Color))
    Sleep(500)
    GUISetBkColor($Color)
    Sleep(500)
WEnd
GUISetBkColor(0)
For $x = 0 To 360 Step 2
    $hue = _Color_SetHue($Color, $x)
    ConsoleWrite("Hue: " & $x & " º" & $hue & @CRLF)
;~  GUISetBkColor($hue)
    GUICtrlSetGraphic($gra,$GUI_GR_COLOR,$hue,$hue)
    GUICtrlSetGraphic($gra,$GUI_GR_RECT,$x,0,2,20)
    GUICtrlSetGraphic($gra,$GUI_GR_REFRESH)
    Sleep(30)
 
Next
Sleep(500)
GUISetBkColor($Color)
GUICtrlDelete($gra)
$gra = GUICtrlCreateGraphic(0,0,350,20)
$gra2 = GUICtrlCreateGraphic(0,20,350,20)
 
 
ConsoleWrite("  Saturation:  Brightness:" & @CRLF)
For $x = 0 To 100
    $sat = _Color_SetSaturation($Color, $x)
    $brigth = _Color_SetBrightness($Color, $x)
    ConsoleWrite($x & " % " & $sat & "   " & $brigth & @CRLF)
    GUICtrlSetGraphic($gra,$GUI_GR_COLOR,$sat,$sat)
    GUICtrlSetGraphic($gra2,$GUI_GR_COLOR,$brigth,$brigth)
    GUICtrlSetGraphic($gra,$GUI_GR_RECT,350*$x/100,0,Ceiling (350/100),20)
    GUICtrlSetGraphic($gra2,$GUI_GR_RECT,350*$x/100,0,Ceiling( 350/100),20)
    GUICtrlSetGraphic($gra,$GUI_GR_REFRESH)
    GUICtrlSetGraphic($gra2,$GUI_GR_REFRESH)
    Sleep(30)
Next
 
Func _Color_SetSaturation($iColor, $nPercent)
    Local $aColorArray[4]
    $nPercent = 1 - ($nPercent / 100)
 
    $aColorArray[1] = _ColorGetRed($iColor)
    $aColorArray[2] = _ColorGetGreen($iColor)
    $aColorArray[3] = _ColorGetBlue($iColor)
 
    If $aColorArray[1] = $aColorArray[2] And $aColorArray[2] = $aColorArray[3] Then Return -1
 
    $IndexMax = _ArrayMaxIndex($aColorArray, 1, 1)
    $IndexMin = _ArrayMinIndex($aColorArray, 1, 1)
    $IndexMid = 6 - ($IndexMax + $IndexMin)
 
    $aColorArray[$IndexMid] = ($aColorArray[$IndexMax] * ($aColorArray[$IndexMid] - $aColorArray[$IndexMin])) / ($aColorArray[$IndexMax] - $aColorArray[$IndexMin])
    $aColorArray[$IndexMid] = Round($aColorArray[$IndexMid] + ($aColorArray[$IndexMax] - $aColorArray[$IndexMid]) * $nPercent, 0)
 
    $aColorArray[$IndexMin] = Round($aColorArray[$IndexMax] * $nPercent, 0)
    Return 0 & "x" & Hex($aColorArray[1], 2) & Hex($aColorArray[2], 2) & Hex($aColorArray[3], 2)
EndFunc   ;==>_Color_SetSaturation
 
Func _Color_GetSaturation($iColor)
    Local $aColorArray[4]
 
    $aColorArray[1] = _ColorGetRed($iColor)
    $aColorArray[2] = _ColorGetGreen($iColor)
    $aColorArray[3] = _ColorGetBlue($iColor)
 
    $IndexMax = _ArrayMaxIndex($aColorArray, 1, 1)
    $IndexMin = _ArrayMinIndex($aColorArray, 1, 1)
    $IndexMid = 6 - ($IndexMax + $IndexMin)
    Return Round((1 - $aColorArray[$IndexMin] / $aColorArray[$IndexMax]) * 100, 0)
EndFunc   ;==>_Color_GetSaturation
 
Func _Color_SetBrightness($iColor, $nPercent)
    Local $aColorArray[4]
    $nPercent = $nPercent / 100
 
    $aColorArray[1] = _ColorGetRed($iColor)
    $aColorArray[2] = _ColorGetGreen($iColor)
    $aColorArray[3] = _ColorGetBlue($iColor)
 
    $IndexMax = _ArrayMaxIndex($aColorArray, 1, 1)
    $ActBrightness = $aColorArray[$IndexMax] / 255
    For $i = 1 To 3
        $aColorArray[$i] = Round($aColorArray[$i] * $nPercent / $ActBrightness, 0)
    Next
    Return 0 & "x" & Hex($aColorArray[1], 2) & Hex($aColorArray[2], 2) & Hex($aColorArray[3], 2)
EndFunc   ;==>_Color_SetBrightness
 
Func _Color_GetBrightness($iColor)
    Local $aColorArray[4]
 
    $aColorArray[1] = _ColorGetRed($iColor)
    $aColorArray[2] = _ColorGetGreen($iColor)
    $aColorArray[3] = _ColorGetBlue($iColor)
 
    $IndexMax = _ArrayMaxIndex($aColorArray, 1, 1)
    Return Round(($aColorArray[$IndexMax] / 255) * 100, 0)
EndFunc   ;==>_Color_GetBrightness
 
Func _Color_SetHue($iColor, $iHue)
    Local $aColorArray[4]
 
    $aColorArray[1] = _ColorGetRed($iColor)
    $aColorArray[2] = _ColorGetGreen($iColor)
    $aColorArray[3] = _ColorGetBlue($iColor)
 
    $iMax = _ArrayMax($aColorArray, 1, 1)
    $iMin = _ArrayMin($aColorArray, 1, 1)
 
    If $iHue >= 61 And $iHue <= 180 Then
        $IndexMax = 2
        If $iHue < 120 Then
            $IndexMin = 3
            $iMid = (($iMax - $iMin) * (120 - $iHue)) / 60 + $iMin
        Else
            $IndexMin = 1
            $iMid = (($iMax - $iMin) * ($iHue - 120)) / 60 + $iMin
        EndIf
    ElseIf $iHue >= 181 And $iHue <= 299 Then
        $IndexMax = 3
        If $iHue <= 240 Then
            $IndexMin = 1
            $iMid = (($iMax - $iMin) * (240 - $iHue)) / 60 + $iMin
        Else
            $IndexMin = 2
            $iMid = (($iMax - $iMin) * ($iHue - 240)) / 60 + $iMin
        EndIf
    ElseIf $iHue >= 300 Or $iHue <= 60 Then
        $IndexMax = 1
        If $iHue <= 60 Then
            $IndexMin = 3
            $iMid = (($iMax - $iMin) * ($iHue)) / 60 + $iMin
        Else
            $IndexMin = 2
            $iMid = (($iMax - $iMin) * (360 - $iHue)) / 60 + $iMin
        EndIf
    EndIf
    $IndexMid = 6 - ($IndexMin + $IndexMax)
    $aColorArray[$IndexMin] = $iMin
    $aColorArray[$IndexMax] = $iMax
    $aColorArray[$IndexMid] = $iMid
    Return 0 & "x" & Hex($aColorArray[1], 2) & Hex($aColorArray[2], 2) & Hex($aColorArray[3], 2)
EndFunc   ;==>_Color_SetHue
 
Func _Color_GetHue($iColor)
    Local $aColorArray[4], $Hue
 
    $aColorArray[1] = _ColorGetRed($iColor)
    $aColorArray[2] = _ColorGetGreen($iColor)
    $aColorArray[3] = _ColorGetBlue($iColor)
 
    $IndexMax = _ArrayMaxIndex($aColorArray, 1, 1)
    $IndexMin = _ArrayMinIndex($aColorArray, 1, 1)
    $IndexMid = 6 - ($IndexMax + $IndexMin)
    $Lambda = ($aColorArray[$IndexMid] - $aColorArray[$IndexMin]) * 60 / ($aColorArray[$IndexMax] - $aColorArray[$IndexMin])
 
    Switch $IndexMax
        Case 1
            Switch $IndexMin
                Case 2
                    $Hue = 360 - $Lambda
                Case 3
                    $Hue = $Lambda
            EndSwitch
        Case 2
            Switch $IndexMin
                Case 1
                    $Hue = 120 + $Lambda
                Case 3
                    $Hue = 120 - $Lambda
            EndSwitch
        Case 3
            Switch $IndexMin
                Case 1
                    $Hue = 240 - $Lambda
                Case 2
                    $Hue = 240 + $Lambda
            EndSwitch
    EndSwitch
    Return Round($Hue, 0)
EndFunc   ;==>_Color_GetHue
 
Func _Color_FindComplementary($iColor)
    Local $iHue = Mod(_Color_GetHue($iColor) + 180, 360)
    Return _Color_SetHue($iColor, $iHue)
EndFunc   ;==>_Color_FindComplementary

However, I dont quite understand the hue changing function in this, or the brightness function. Are there any easier ways to do something like this? Otherwise, can someone please help me make sense of the hue and brightness functions?

Thanks.

Finally the autoit tags are working so there u go. Sorry bouth that, it was only showing the first few lines and then it swallowed up the edit button and all those buttons and so on.

Edited by Mikeman27294

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Try passing the code, after first switching the post editor in code mode. An post it in that mode to(if posting in normal mode also screws things up.) ...

Erm: Yep ... Don't post in Normal mode ;)

Grr: ... don't even switch to normal mode ... :graduated:

test: (will be removed again) (guess not yet ... )

#include<Array.au3>
#include<Color.au3>
#include<GUIConstantsEx.au3>


GUICreate("", 360, 350)
$gra = GUICtrlCreateGraphic(0, 0, 360, 20)
GUISetState()
$Color = 0xFFff00
GUISetBkColor($Color)
ConsoleWrite("Color: 0x" & Hex($Color, 6) & @CRLF)
ConsoleWrite("Saturation: " & _Color_GetSaturation($Color) & " %" & @CRLF)
ConsoleWrite("Brightness: " & _Color_GetBrightness($Color) & " %" & @CRLF)
ConsoleWrite("Hue: " & _Color_GetHue($Color) & " º" & @CRLF)
Sleep(1000)
ConsoleWrite("Complementary color: " & _Color_FindComplementary($Color) & @CRLF & @CRLF)
$i = 0
While $i < 2
    $i += 1
    GUISetBkColor(_Color_FindComplementary($Color))
    Sleep(500)
    GUISetBkColor($Color)
    Sleep(500)
WEnd
GUISetBkColor(0)
For $x = 0 To 360 Step 2
    $Hue = _Color_SetHue($Color, $x)
    ConsoleWrite("Hue: " & $x & " º" & $Hue & @CRLF)
;~ GUISetBkColor($hue)
    GUICtrlSetGraphic($gra, $GUI_GR_COLOR, $Hue, $Hue)
    GUICtrlSetGraphic($gra, $GUI_GR_RECT, $x, 0, 2, 20)
    GUICtrlSetGraphic($gra, $GUI_GR_REFRESH)
    Sleep(30)

Next
Sleep(500)
GUISetBkColor($Color)
GUICtrlDelete($gra)
$gra = GUICtrlCreateGraphic(0, 0, 350, 20)
$gra2 = GUICtrlCreateGraphic(0, 20, 350, 20)


ConsoleWrite("  Saturation: Brightness:" & @CRLF)
For $x = 0 To 100
    $sat = _Color_SetSaturation($Color, $x)
    $brigth = _Color_SetBrightness($Color, $x)
    ConsoleWrite($x & " % " & $sat & "   " & $brigth & @CRLF)
    GUICtrlSetGraphic($gra, $GUI_GR_COLOR, $sat, $sat)
    GUICtrlSetGraphic($gra2, $GUI_GR_COLOR, $brigth, $brigth)
    GUICtrlSetGraphic($gra, $GUI_GR_RECT, 350 * $x / 100, 0, Ceiling(350 / 100), 20)
    GUICtrlSetGraphic($gra2, $GUI_GR_RECT, 350 * $x / 100, 0, Ceiling(350 / 100), 20)
    GUICtrlSetGraphic($gra, $GUI_GR_REFRESH)
    GUICtrlSetGraphic($gra2, $GUI_GR_REFRESH)
    Sleep(30)
Next

Func _Color_SetSaturation($iColor, $nPercent)
    Local $aColorArray[4]
    $nPercent = 1 - ($nPercent / 100)

    $aColorArray[1] = _ColorGetRed($iColor)
    $aColorArray[2] = _ColorGetGreen($iColor)
    $aColorArray[3] = _ColorGetBlue($iColor)

    If $aColorArray[1] = $aColorArray[2] And $aColorArray[2] = $aColorArray[3] Then Return -1

    $IndexMax = _ArrayMaxIndex($aColorArray, 1, 1)
    $IndexMin = _ArrayMinIndex($aColorArray, 1, 1)
    $IndexMid = 6 - ($IndexMax + $IndexMin)

    $aColorArray[$IndexMid] = ($aColorArray[$IndexMax] * ($aColorArray[$IndexMid] - $aColorArray[$IndexMin])) / ($aColorArray[$IndexMax] - $aColorArray[$IndexMin])
    $aColorArray[$IndexMid] = Round($aColorArray[$IndexMid] + ($aColorArray[$IndexMax] - $aColorArray[$IndexMid]) * $nPercent, 0)

    $aColorArray[$IndexMin] = Round($aColorArray[$IndexMax] * $nPercent, 0)
    Return 0 & "x" & Hex($aColorArray[1], 2) & Hex($aColorArray[2], 2) & Hex($aColorArray[3], 2)
EndFunc ;==>_Color_SetSaturation

Func _Color_GetSaturation($iColor)
    Local $aColorArray[4]

    $aColorArray[1] = _ColorGetRed($iColor)
    $aColorArray[2] = _ColorGetGreen($iColor)
    $aColorArray[3] = _ColorGetBlue($iColor)

    $IndexMax = _ArrayMaxIndex($aColorArray, 1, 1)
    $IndexMin = _ArrayMinIndex($aColorArray, 1, 1)
    $IndexMid = 6 - ($IndexMax + $IndexMin)
    Return Round((1 - $aColorArray[$IndexMin] / $aColorArray[$IndexMax]) * 100, 0)
EndFunc ;==>_Color_GetSaturation

Func _Color_SetBrightness($iColor, $nPercent)
    Local $aColorArray[4]
    $nPercent = $nPercent / 100

    $aColorArray[1] = _ColorGetRed($iColor)
    $aColorArray[2] = _ColorGetGreen($iColor)
    $aColorArray[3] = _ColorGetBlue($iColor)

    $IndexMax = _ArrayMaxIndex($aColorArray, 1, 1)
    $ActBrightness = $aColorArray[$IndexMax] / 255
    For $i = 1 To 3
        $aColorArray[$i] = Round($aColorArray[$i] * $nPercent / $ActBrightness, 0)
    Next
    Return 0 & "x" & Hex($aColorArray[1], 2) & Hex($aColorArray[2], 2) & Hex($aColorArray[3], 2)
EndFunc ;==>_Color_SetBrightness

Func _Color_GetBrightness($iColor)
    Local $aColorArray[4]

    $aColorArray[1] = _ColorGetRed($iColor)
    $aColorArray[2] = _ColorGetGreen($iColor)
    $aColorArray[3] = _ColorGetBlue($iColor)

    $IndexMax = _ArrayMaxIndex($aColorArray, 1, 1)
    Return Round(($aColorArray[$IndexMax] / 255) * 100, 0)
EndFunc ;==>_Color_GetBrightness

Func _Color_SetHue($iColor, $iHue)
    Local $aColorArray[4]

    $aColorArray[1] = _ColorGetRed($iColor)
    $aColorArray[2] = _ColorGetGreen($iColor)
    $aColorArray[3] = _ColorGetBlue($iColor)

    $iMax = _ArrayMax($aColorArray, 1, 1)
    $iMin = _ArrayMin($aColorArray, 1, 1)

    If $iHue >= 61 And $iHue <= 180 Then
        $IndexMax = 2
        If $iHue < 120 Then
            $IndexMin = 3
            $iMid = (($iMax - $iMin) * (120 - $iHue)) / 60 + $iMin
        Else
            $IndexMin = 1
            $iMid = (($iMax - $iMin) * ($iHue - 120)) / 60 + $iMin
        EndIf
    ElseIf $iHue >= 181 And $iHue <= 299 Then
        $IndexMax = 3
        If $iHue <= 240 Then
            $IndexMin = 1
            $iMid = (($iMax - $iMin) * (240 - $iHue)) / 60 + $iMin
        Else
            $IndexMin = 2
            $iMid = (($iMax - $iMin) * ($iHue - 240)) / 60 + $iMin
        EndIf
    ElseIf $iHue >= 300 Or $iHue <= 60 Then
        $IndexMax = 1
        If $iHue <= 60 Then
            $IndexMin = 3
            $iMid = (($iMax - $iMin) * ($iHue)) / 60 + $iMin
        Else
            $IndexMin = 2
            $iMid = (($iMax - $iMin) * (360 - $iHue)) / 60 + $iMin
        EndIf
    EndIf
    $IndexMid = 6 - ($IndexMin + $IndexMax)
    $aColorArray[$IndexMin] = $iMin
    $aColorArray[$IndexMax] = $iMax
    $aColorArray[$IndexMid] = $iMid
    Return 0 & "x" & Hex($aColorArray[1], 2) & Hex($aColorArray[2], 2) & Hex($aColorArray[3], 2)
EndFunc ;==>_Color_SetHue

Func _Color_GetHue($iColor)
    Local $aColorArray[4], $Hue

    $aColorArray[1] = _ColorGetRed($iColor)
    $aColorArray[2] = _ColorGetGreen($iColor)
    $aColorArray[3] = _ColorGetBlue($iColor)

    $IndexMax = _ArrayMaxIndex($aColorArray, 1, 1)
    $IndexMin = _ArrayMinIndex($aColorArray, 1, 1)
    $IndexMid = 6 - ($IndexMax + $IndexMin)
    $Lambda = ($aColorArray[$IndexMid] - $aColorArray[$IndexMin]) * 60 / ($aColorArray[$IndexMax] - $aColorArray[$IndexMin])

    Switch $IndexMax
        Case 1
            Switch $IndexMin
                Case 2
                    $Hue = 360 - $Lambda
                Case 3
                    $Hue = $Lambda
            EndSwitch
        Case 2
            Switch $IndexMin
                Case 1
                    $Hue = 120 + $Lambda
                Case 3
                    $Hue = 120 - $Lambda
            EndSwitch
        Case 3
            Switch $IndexMin
                Case 1
                    $Hue = 240 - $Lambda
                Case 2
                    $Hue = 240 + $Lambda
            EndSwitch
    EndSwitch
    Return Round($Hue, 0)
EndFunc ;==>_Color_GetHue

Func _Color_FindComplementary($iColor)
    Local $iHue = Mod(_Color_GetHue($iColor) + 180, 360)
    Return _Color_SetHue($iColor, $iHue)
EndFunc ;==>_Color_FindComplementary

Last 'Done' (I Hope) edit ... yep. (all edit-code mode, no normal edit-mode involved.)

Edited by iEvKI3gv9Wrkd41u

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites

Thanks guys. That image tool looks like it is exactly what will answer my question.

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

  • Similar Content

    • nbg15
      tesseract doesnt detect the easiest image *image to text*
      By nbg15
      Hello everybody..
       
      i have this picture here *attached* and this script here: 
       
      $ImageToReadPath = @MyDocumentsDir & "\GDIPlus_Image2.jpg" $ResultTextPath = @MyDocumentsDir & "\Result" $OutPutPath = $ResultTextPath & ".txt" $TesseractExePath = @MyDocumentsDir & "\Tesseract.exe" ShellExecuteWait($TesseractExePath, '"' & $ImageToReadPath & '" "' & $ResultTextPath & '"', "", "", @SW_HIDE) If @error Then Exit MsgBox(0, "Error", @error) EndIf MsgBox(0, "Result", FileRead($OutPutPath)) FileDelete($OutPutPath)  
      but tesseract doesnt recognized the correct word... and gives me trash back...

      this is the image >> 
      and the result was >> "samm" 

      the image was an normal jpg and generated with this code here:
       
      _ScreenCapture_Capture(@MyDocumentsDir & "\GDIPlus_Image2.jpg", 712,268,853,284)
      Could anybody give me a hint what i can do better to get this easy image to text?
       
      thank u very much!!!
       
       
      Edit: i also tried to capture the screen as bmp with a higher resolution... nothing changed... 
       
       
      _ScreenCapture_SetBMPFormat(4) _ScreenCapture_Capture(@MyDocumentsDir & "\GDIPlus_Image.bmp", 712,279,853,295)  
    • RyukShini
      Image quality is bad compared to paint
      By RyukShini
      #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=car.ico #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <GDIPlus.au3> #include <File.au3> #include <Array.au3> #include <ColorConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ProgressConstants.au3> ; Declare array Dim $Images[1] ; Gets all JPG files in the current directory (@ScriptDir). Local $search = FileFindFirstFile("*.jpg") ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No JPG files could be found.") Exit EndIf ; Resize array While 1 If IsArray($Images) Then Local $Bound = UBound($Images) ReDim $Images[$Bound+1] EndIf $Images[$Bound] = FileFindNextFile($search) If @error Then ExitLoop WEnd ; Close the search handle FileClose($search) ; Create directory "resized" if not there yet $nymappe = InputBox("Mappe / Bil Navn", "Mappe / Bil Navn") If NOT FileExists(@ScriptDir & "\" & $nymappe & "\") Then DirCreate(@ScriptDir & "\" & $nymappe & "\") EndIf ; Loop for JPGs - gets dimension of JPG and calls resize function to resize to 50% width and 50% height For $i = 1 to Ubound($Images)-1 If $Images[$i] <> "" AND FileExists(@ScriptDir & "\" & $Images[$i]) Then Local $ImagePath = @ScriptDir & "\" & $Images[$i] _GDIPlus_Startup() Local $hImage = _GDIPlus_ImageLoadFromFile($ImagePath) Local $ImageWidth = _GDIPlus_ImageGetWidth($hImage) Local $ImageHeight = _GDIPlus_ImageGetHeight($hImage) _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() ;MsgBox(0,"DEBUG", $ImageWidth & " x " & $ImageHeight) Local $NewImageWidth = ($ImageWidth / 100) * 15 Local $NewImageHeight = ($ImageHeight / 100) * 15 ;MsgBox(0,"DEBUG: " & $i,$Images[$i]) _ImageResize(@ScriptDir & "\" & $Images[$i], @ScriptDir & "\" & $nymappe & "\" & $Images[$i], $NewImageWidth, $NewImageHeight) EndIf Next ; Resize function Func _ImageResize($sInImage, $sOutImage, $iW, $iH) Local $hWnd, $hDC, $hBMP, $hImage1, $hImage2, $hGraphic, $CLSID, $i = 0 ;OutFile path, to use later on. Local $sOP = StringLeft($sOutImage, StringInStr($sOutImage, "\", 0, -1)) ;OutFile name, to use later on. Local $sOF = StringMid($sOutImage, StringInStr($sOutImage, "\", 0, -1) + 1) ;OutFile extension , to use for the encoder later on. Local $Ext = StringUpper(StringMid($sOutImage, StringInStr($sOutImage, ".", 0, -1) + 1)) ; Win api to create blank bitmap at the width and height to put your resized image on. $hWnd = _WinAPI_GetDesktopWindow() $hDC = _WinAPI_GetDC($hWnd) $hBMP = _WinAPI_CreateCompatibleBitmap($hDC, $iW, $iH) _WinAPI_ReleaseDC($hWnd, $hDC) ;Start GDIPlus _GDIPlus_Startup() ;Get the handle of blank bitmap you created above as an image $hImage1 = _GDIPlus_BitmapCreateFromHBITMAP ($hBMP) ;Load the image you want to resize. $hImage2 = _GDIPlus_ImageLoadFromFile($sInImage) ;Get the graphic context of the blank bitmap $hGraphic = _GDIPlus_ImageGetGraphicsContext ($hImage1) ;Draw the loaded image onto the blank bitmap at the size you want _GDIPLus_GraphicsDrawImageRect($hGraphic, $hImage2, 0, 0, $iW, $iH) ;Get the encoder of to save the resized image in the format you want. $CLSID = _GDIPlus_EncodersGetCLSID($Ext) ;Generate a number for out file that doesn't already exist, so you don't overwrite an existing image. Do $i += 1 Until (Not FileExists($sOP & $i & "_" & $sOF)) ;Prefix the number to the begining of the output filename $sOutImage = $sOP & $i & "_" & $sOF ;Save the new resized image. _GDIPlus_ImageSaveToFileEx($hImage1, $sOutImage, $CLSID) ;Clean up and shutdown GDIPlus. _GDIPlus_ImageDispose($hImage1) _GDIPlus_ImageDispose($hImage2) _GDIPlus_GraphicsDispose ($hGraphic) _WinAPI_DeleteObject($hBMP) _GDIPlus_Shutdown() EndFunc Quality gets quite bad compared to using Paint / Photoshop when resizing with GDIPlus
      Any idea how to make the quality better?
      Thanks in advance
    • UEZ
      _GDIPlus_BitmapApplyFilter UDF beta
      By UEZ
      A collection of image filter effects usable with AutoIt!
       
      IMPORTANT: You are not allowed to sell this code or just parts of it in a commercial project or modify it and distribute it with a different name!
      Distributing copies of this UDF incl. _GDIPlus_BitmapApplyFilter.dll in compiled format (exe) must be free of any fee!
       
      More information can be found in the forum thread!
       
    • Katie_Deely
      Getting image dimensions
      By Katie_Deely
      Hi there. Sorry to bother again. I don't get the tutorials and examples...
      Let's say I want to display an image "E:\img\123.jpg" in a GUI. Usually I'd do that by using GUICtrlCreatePic($path, $x, $y, $width, $height).
      Unfortunately, the width and height are changing with every picture and they are unknown as well...
      First of all, how I can get the width and height of a given picture?
      And is there any way that doesn't require me to constantly delete and create that window from scratch? 
      Thanks!
    • Lasker
      A new image search solution
      By Lasker
      Hello,
      Im a new AutoIt user, im from Spain and i would like to share here my own image search detection method.
      What's about it?
      It's not perfect, but with it you don't need to use any DLL file. You don't need to distribute the image file with your final AU3 Script, or Exe if compiled. The image size does not affect to the detection speed. It's bug free (i believe).
      You can find here as an attach file, a distro package with all you need, and it includes a simple how-to guide.
      Im going to paste here the how-to guide:
      How to use this AutoIt image detector:
      Point 1:
      Install JRE (Java Runtime Environment), without this you can't execute Java Applications (.jar files). Open the Java tool named AISD with double click on it, or "java -jar aisd.jar" in the cmd. In AISD, open the image you want to detect in your script. Remember: the upper left pixel of the image, MUST be a not common color in the background if you want a fast detection. Then you will get a script file if you want, or only a clipboard copied version, full ready to paste into your main script because this one comes with extra help codes. Anyway, the generated code is the $sign definition of the image (calm down, point 3 explains what is the $sign and it's easy).
      Point 2:
      Paste the mentioned code in your main script, and try to follow the sample_usage script. If you know how to write au3 codes, it should be very easy. In general terms, all you need is to include image_search.au3, and then you can use the func image_search($sign, $width, $height). You need also the get_image_sign() function, that calculates the first parameter for image_search(). The get_image_sign() function is the one you have generated at point 1.
      Point 3:
      image_search() returns the center point of the target image. The func needs the $sign from the image, width and height. This $sign is the "footprint" of the image, in the form of an array of 9 integers. In most of the cases the $sign should be enough to identify the image, this is useful because using the $sign instead of the real image let you get a small script and a fast detection. You can also delete the image once you get the $sign. This $sign has always the same size (those 9 integers, it does not matter if the original image is small or big). How can you define the $sign for a certain image?, you don't need to generate the $sign, AISD does (point 1). Follow the sample_usage script and you will get it.
      Files in this distro package:
      * AISD.jar: The already explained Java app.
      * image_search.au3: The library or module with the resources that lets you detect images.
      * sample_usage.au3: The mentioned sample_usage script. It contains the smallest example, but i think it should be ok for learning purposes.
      * sample_usage.exe: The sample_usage.au3 script compiled (au3 -> .exe). You can execute this to see the image_search() func working.
      * sample_target.png: The image to be detected in the sample_usage. You can delete this file and the script will be fine.
      * OffsetCalc.jar: It's only a Java tool to calculate the offset to transform an XY point into another one. It's useful if you want to use apply_offset function (from image_search.au3). Both things are only necessary when it's hard to find a version of the target image with upper left pixel in the way mentioned. As you can imagine, the idea is to detect another image and then apply the offset to get the real coordinates of the original target image.
      Happy Detections
      Lasker image_search.zip