Jump to content
RyukShini

MS Paint, change size for multiple files and save to path

Recommended Posts

RyukShini

Hello AutoIT masters

I am gonna start writing a fun little script to resize X amount of images with the Horizontal/Vertical aspects to 15/15 instead of the standard 100/100
558ca72d2279f09a94df64f9ca623a2a.png

I need to be able to do this with X amount of images and after changing the dimensions I need to save all the images in a path.
so to keep things simple.

1: File open prompt
2: Choose X amount of images
3: Automatically choose 15/15 for all images
4: Save in path chosen by user
5: Might be more to come.
6: the faster the better!
 

I am gonna start this project tomorrow, any help/references is highly appreciated!

Thanks in advance and Wish me luck;)

 

 

#### I Hit a bump on the road ###

I successfully manage to do what I want to do and I successfully manage to rewrite names but 3 of the image names won't rename?

So lets say I have 10 images that all get resized, then 7 of them gets renamed but not the last three, confuses me quite a bit?
Thanks in advance!
Rename script:
 

Func renameall()
local $path = @ScriptDir & "\" & $nymappe & "\"
local $ret
Local $hSearch = FileFindFirstFile($path & "*.jpg")
$i = 1
While 1
    $sFileName = FileFindNextFile($hSearch)
    If @error Then ExitLoop
    if FileMove($path & $sFileName, $path & String("NewName" & +$i) & ".jpg", 0) = 1 then
        ConsoleWrite($path & $sFileName & ' renamed to ' & $path & String("NewName" & +$i) & ".jpg" & @LF)
    Else
        ConsoleWrite('File rename failed for file = ' & $path & $sFileName & @LF)
    endif
    $i += 1
WEnd
FileClose($hSearch)
EndFunc

Full script:

#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()
    Call("renameall")
EndFunc

Func renameall()
local $path = @ScriptDir & "\" & $nymappe & "\"
local $ret
Local $hSearch = FileFindFirstFile($path & "*.jpg")
$i = 1
While 1
    $sFileName = FileFindNextFile($hSearch)
    If @error Then ExitLoop
    if FileMove($path & $sFileName, $path & String("NewName" & +$i) & ".jpg", 0) = 1 then
        ConsoleWrite($path & $sFileName & ' renamed to ' & $path & String("NewName" & +$i) & ".jpg" & @LF)
    Else
        ConsoleWrite('File rename failed for file = ' & $path & $sFileName & @LF)
    endif
    $i += 1
WEnd
FileClose($hSearch)
EndFunc

 

Edited by RyukShini
Hit a bump....

Share this post


Link to post
Share on other sites
water

To resize images use IrfanView ;)
Has a batch mode to do this on a lot of images.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
RyukShini
1 minute ago, water said:

To resize images use IrfanView ;)
Has a batch mode to do this on a lot of images.

Thanks but I could easily do this on photoshop as well using a macro or whatever.
but I am looking to do this only by using AutoIT and MS Paint since it is a project to ease the tasks my brother do in he's company.
Anyways thanks a lot for the suggestion @water
I will also be uploading all files to a site, but thats when everything else runs ;)

Share this post


Link to post
Share on other sites
ViciousXUSMC

I use irfanview as well, and while batch is fine for me as a techy guy if I really want to hold the hand of a user for a specific task I have automated it with autoit. 

Share this post


Link to post
Share on other sites
Synapsee
Quote

with the Horizontal/Vertical aspects to 15/15 instead of the standard 100/100

15 / 15 = 1
100 / 100 = 1

i can't understand

Share this post


Link to post
Share on other sites
RyukShini
1 minute ago, Synapsee said:
15 / 15 = 1
100 / 100 = 1

i can't understand

Sorry if I am being unclear, I haven't written any code yet :)
I will start tmr, heading home now.
but to keep things short!
I am in need of opening say 10 image files.
After opening the images I need to Resize the images(Just automatically input 15 in the horizontal which will automatically change the vertical to 15 as well, since it maintains the aspects)
After changing the values of all 10 images I need a Save As prompt to open and I would be able to choose where to save the 10 edited images.
dafa40c9a686c7904b821f36dd95f5c6.gif

826fb8dc39014ece89e3dc2ad4b2ecb5.gif

 

 

Share this post


Link to post
Share on other sites
Synapsee

so a 1000x1000 pixel img, give a 150x150 pixel img ?

i have this script on my drive, resize image if > 800x800 to 800x800.

u can probably adapt it for u.

something like :

pseudo code :

_ImageResize($sInImage, $sOutImage, $iW * 0.15, $iH * 0.15)

 

main code source :

my script :

#include <GDIPlus.au3>
#include <File.au3>

Func _ArrayAddColumns(ByRef $aArr, $iNumColToAdd = 1)
    If IsArray($aArr) = 0 Then Return SetError(1, 0, -1) ; Filter out non-array
    If $iNumColToAdd < 1 Then Return SetError(2, 0, -1) ; $iNumColToAdd must be greater than zero to add a column.
    If UBound($aArr, 0) > 2 Then Return SetError(3, 0, -1) ; Only allows a 1d or 2d array pass this line.

    If UBound($aArr, 0) = 1 Then ; ====== For 1d array ========
        Local $aRet[UBound($aArr)][$iNumColToAdd + 1] ; Create new 2d array.
        For $r = 0 To UBound($aArr) - 1
            $aRet[$r][0] = $aArr[$r]
        Next
    Else ; ======= For 2d array ============
        Local $aRet = $aArr ; So that ByRef $aArr is not altered outside of function.
        ReDim $aRet[UBound($aRet)][UBound($aRet, 2) + $iNumColToAdd] ; ReDim 2d array only.
    EndIf

    Return $aRet
EndFunc   ;==>_ArrayAddColumns

$list = _FileListToArrayRec("..\Crop","*.jpg;*.jpeg",0,0,0,2)
$list_filename = _FileListToArrayRec("..\Crop","*.jpg;*.jpeg",0,0,0,0)
$list = _ArrayAddColumns($list, 2)
;_ArrayDisplay($list)

for $i = 1 to UBound($list)-1

_GDIPlus_Startup()
$FileLoad = _GDIPlus_ImageLoadFromFile(_PathFull($list[$i][0]))
$h = _GDIPlus_ImageGetHeight($FileLoad)
$w = _GDIPlus_ImageGetWidth($FileLoad)
_GDIPlus_Shutdown()

$list[$i][1] = $w
$list[$i][2] = $h

next

_ArrayDisplay($list)

for $i = 1 to UBound($list)-1

    $temp = @ScriptDir & "\" & $list_filename[$i]
    $temp_resize = StringReplace($temp, ".jpeg", ".jpg")

    if $list[$i][1] = $list[$i][2] Then
        if $list[$i][1] > 800 Then
            _ImageResize($list[$i][0], $temp_resize, 800, 800)
        Else
            FileCopy($list[$i][0], $temp)
        endif
    Else
        ;Get Min
        if $list[$i][1] < $list[$i][2] Then
            if  $list[$i][1] > 800 then
                _ImageResize($list[$i][0], $temp_resize, 800, 800)
            Else
                _ImageResize($list[$i][0], $temp_resize, $list[$i][1], $list[$i][1])
            endif
        Else
            if  $list[$i][2] > 800 then
                _ImageResize($list[$i][0], $temp_resize, 800, 800)
            Else
                _ImageResize($list[$i][0], $temp_resize, $list[$i][2], $list[$i][2])
            endif
        Endif
    endif

next

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

    $sOutImage = $sOP & $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

Exit




;135

 

Share this post


Link to post
Share on other sites
RyukShini
8 minutes ago, Synapsee said:

so a 1000x1000 pixel img, give a 150x150 pixel img ?

i have this script on my drive, resize image if > 800x800 to 800x800.

u can probably adapt it for u.

something like :

pseudo code :

_ImageResize($sInImage, $sOutImage, $iW * 0.15, $iH * 0.15)

 

main code source :

my script :

#include <GDIPlus.au3>
#include <File.au3>

Func _ArrayAddColumns(ByRef $aArr, $iNumColToAdd = 1)
    If IsArray($aArr) = 0 Then Return SetError(1, 0, -1) ; Filter out non-array
    If $iNumColToAdd < 1 Then Return SetError(2, 0, -1) ; $iNumColToAdd must be greater than zero to add a column.
    If UBound($aArr, 0) > 2 Then Return SetError(3, 0, -1) ; Only allows a 1d or 2d array pass this line.

    If UBound($aArr, 0) = 1 Then ; ====== For 1d array ========
        Local $aRet[UBound($aArr)][$iNumColToAdd + 1] ; Create new 2d array.
        For $r = 0 To UBound($aArr) - 1
            $aRet[$r][0] = $aArr[$r]
        Next
    Else ; ======= For 2d array ============
        Local $aRet = $aArr ; So that ByRef $aArr is not altered outside of function.
        ReDim $aRet[UBound($aRet)][UBound($aRet, 2) + $iNumColToAdd] ; ReDim 2d array only.
    EndIf

    Return $aRet
EndFunc   ;==>_ArrayAddColumns

$list = _FileListToArrayRec("..\Crop","*.jpg;*.jpeg",0,0,0,2)
$list_filename = _FileListToArrayRec("..\Crop","*.jpg;*.jpeg",0,0,0,0)
$list = _ArrayAddColumns($list, 2)
;_ArrayDisplay($list)

for $i = 1 to UBound($list)-1

_GDIPlus_Startup()
$FileLoad = _GDIPlus_ImageLoadFromFile(_PathFull($list[$i][0]))
$h = _GDIPlus_ImageGetHeight($FileLoad)
$w = _GDIPlus_ImageGetWidth($FileLoad)
_GDIPlus_Shutdown()

$list[$i][1] = $w
$list[$i][2] = $h

next

_ArrayDisplay($list)

for $i = 1 to UBound($list)-1

    $temp = @ScriptDir & "\" & $list_filename[$i]
    $temp_resize = StringReplace($temp, ".jpeg", ".jpg")

    if $list[$i][1] = $list[$i][2] Then
        if $list[$i][1] > 800 Then
            _ImageResize($list[$i][0], $temp_resize, 800, 800)
        Else
            FileCopy($list[$i][0], $temp)
        endif
    Else
        ;Get Min
        if $list[$i][1] < $list[$i][2] Then
            if  $list[$i][1] > 800 then
                _ImageResize($list[$i][0], $temp_resize, 800, 800)
            Else
                _ImageResize($list[$i][0], $temp_resize, $list[$i][1], $list[$i][1])
            endif
        Else
            if  $list[$i][2] > 800 then
                _ImageResize($list[$i][0], $temp_resize, 800, 800)
            Else
                _ImageResize($list[$i][0], $temp_resize, $list[$i][2], $list[$i][2])
            endif
        Endif
    endif

next

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

    $sOutImage = $sOP & $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

Exit




;135

 

This is why I love this forum!
Thanks a lot, I can adapt to this script I am sure.
will work on it first thing in the morning.

Share this post


Link to post
Share on other sites
RyukShini

#### I Hit a bump on the road ###

I successfully manage to do what I want to do and I successfully manage to rewrite names but 3 of the image names won't rename?

So lets say I have 10 images that all get resized, then 7 of them gets renamed but not the last three, confuses me quite a bit?
Thanks in advance!

Rename Script:
 

Func renameall()
local $path = @ScriptDir & "\" & $nymappe & "\"
local $ret
Local $hSearch = FileFindFirstFile($path & "*.jpg")
$i = 1
While 1
    $sFileName = FileFindNextFile($hSearch)
    If @error Then ExitLoop
    if FileMove($path & $sFileName, $path & String("NewName" & +$i) & ".jpg", 0) = 1 then
        ConsoleWrite($path & $sFileName & ' renamed to ' & $path & String("NewName" & +$i) & ".jpg" & @LF)
    Else
        ConsoleWrite('File rename failed for file = ' & $path & $sFileName & @LF)
    endif
    $i += 1
WEnd
FileClose($hSearch)
EndFunc

 

Full Script:
 

#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()
    Call("renameall")
EndFunc

Func renameall()
local $path = @ScriptDir & "\" & $nymappe & "\"
local $ret
Local $hSearch = FileFindFirstFile($path & "*.jpg")
$i = 1
While 1
    $sFileName = FileFindNextFile($hSearch)
    If @error Then ExitLoop
    if FileMove($path & $sFileName, $path & String("NewName" & +$i) & ".jpg", 0) = 1 then
        ConsoleWrite($path & $sFileName & ' renamed to ' & $path & String("NewName" & +$i) & ".jpg" & @LF)
    Else
        ConsoleWrite('File rename failed for file = ' & $path & $sFileName & @LF)
    endif
    $i += 1
WEnd
FileClose($hSearch)
EndFunc

 

Edited by RyukShini

Share this post


Link to post
Share on other sites
RyukShini

@water got an idea why??
read above^

 

Thanks in advance.

Share this post


Link to post
Share on other sites
JLogan3o13

@RyukShini when you reply, there is no need to quote every single post above yours. Most of us can remember what we just said, and it pads the thread unnecessarily.

 


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
water

You create an array with all JPG files - FINE
You loop through this array and call function _ImageResize for each entry - FINE
At the end of function _ImageResize  you call function _RenameAll - ??

This means you rename ALL JPG files after the first JPG has been processed.
I think calling _RenameAll should be called at the end of the script or you should rename a single JPG after it has been resized.

BZW: You are calling _GDIPlus_Startup and _GDIPlus_Shutdown multiple times in your script and even in a loop. This sloooooowws down your script.
Call _GDIPlus_Startup  at the top of your script and end GDI+ before you exit.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
RyukShini
19 hours ago, water said:

You create an array with all JPG files - FINE
You loop through this array and call function _ImageResize for each entry - FINE
At the end of function _ImageResize  you call function _RenameAll - ??

This means you rename ALL JPG files after the first JPG has been processed.
I think calling _RenameAll should be called at the end of the script or you should rename a single JPG after it has been resized.

BZW: You are calling _GDIPlus_Startup and _GDIPlus_Shutdown multiple times in your script and even in a loop. This sloooooowws down your script.
Call _GDIPlus_Startup  at the top of your script and end GDI+ before you exit.

Thanks a lot savior!
I am doing this now.

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

  • Similar Content

    • DynamicRookie
      By DynamicRookie

      Welcome to Ailave, future programming project
      --------------------------------------------------------------------------
       
      What's Ailave?
       
       
      Ailave is a suggestions-powered project that focuses in simplifying AutoIt / Au3 codes, Ailave is a code-shortener that will be equipped with lots of functions and constants that will make ur code shorter and more effective, you don't need to type thousands of lines of code to make a GUI or a function, Ailave does the hard work, you only tell him what to do.
      Ailave will include:
      *Lots of Functions that will make ur coding a more comfortable and faster experience
      *GUI'S! > Yes, it will include GUI's templates, creating a script with GUI was never easier!
      *Suggestions-Powered > Suggest me what you want Ailave to have! (Click here for more information)
      *Colors! > It will include a large library of color codes that will be helpful.
       
      You are your own limit to imagination, suggest me an idea!
       
      What benefits Ailave offers?
       
       
      Easy to understand codes, easier debugging, faster coding, more complete functions, more effective and shorter scripts, no need to create lots of functions, no need to code thousands of lines, and an infinite list of benefits you will experiment yourself soon
       
      How Ailave works?
       
      It gives u tons of functions that you can use as individual commands, that way you dont need to create thousands of lines to code more effective scripts.
       
      Where i can download Ailave?
       
      Ailave is still an under-development project and an official version of Ailave won't be released until June, 2018, But you can suggest me ideas.
       
      Click here to see Ailave's project website
       
       
       
       
       
      Want to contribute to Ailave's Development?
       
      We are currently crafting new functions and we would love to hear from you.
       
       
      SUGGEST ME!
       
       
    • UritOR
      By UritOR
      Hi all,
      I'm trying to find how to draw an image (create a label in mspaint) and save it as .bmp. And set it to be a wallpaper
      I also need to know what wallpaper is use now, for restore it when the script is closed.
      What is the best way to do it? Do I need Gdi+ for it?  I use this code (which I found here in forum) to set a .bmp file as wallpaper:
      Func _ChangeWallpaper($sFile,$iType) ; Changes the wallpaper to $sFilename using $iType as: ; 1 Tiled ; 2 Centered ; 3 Stretched ; any other value (usually 0) unchanged ; ; Returns ; 0 if everything is allright. ; -1 if $sFile does not exist. @error is set to 1 ; -2 if £sFile is not a .bmp file. @error is set to 2 If Not FileExists($sFile) Then SetError(1) Return -1 EndIf If StringTrimLeft($sFile,StringInStr($sFile,'.',0,-1)) <> 'bmp' Then SetError(2) Return -2 EndIf Select Case $iType = 1 RegWrite('HKCU\Control Panel\Desktop','TileWallpaper','reg_sz','1') RegWrite('HKCU\Control Panel\Desktop','WallpaperStyle','reg_sz','0') Case $iType = 2 RegWrite('HKCU\Control Panel\Desktop','TileWallpaper','reg_sz','0') RegWrite('HKCU\Control Panel\Desktop','WallpaperStyle','reg_sz','0') Case $iType = 3 RegWrite('HKCU\Control Panel\Desktop','TileWallpaper','reg_sz','0') RegWrite('HKCU\Control Panel\Desktop','WallpaperStyle','reg_sz','2') Case Else EndSelect RegWrite('HKCU\Control Panel\Desktop','Wallpaper','reg_sz',$sFile) DllCall("User32.dll","int","SystemParametersInfo","int",20,"int",0,"str",$sFile,"int",0) Return 0 EndFunc  
      The flow that I understand should be:
      1) Check what wallpaper is in use now. I can find the path to it by going to registry  key named "wallpaper" here :[HKEY_CURRENT_USER\Control Panel\Desktop]
      2) Create a file mspaint
      3) Create a label with its properties (size,color) in this file
      3) Save this file in some temporary directory
      4) Set a created file as a wallpaper using the above code
      5) When the script is closed restore the old wallpaper.
       
      So again, my question is how to create a .bmp file with label in it?
    • RyukShini
      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
    • InunoTaishou
      By InunoTaishou
      Hello again the AutoIt Forums! I've gotten really addicted to the GDIPlus stuff and I'm trying to do more. Trying to create small editor using GDIPlus and I'm a bit lost just getting started.
      The main GUI is small, so when I you Snip an area that's larger than the GUI it would only display as large as the GUI (I got around this by setting an event for WM_WINDOWPOSCHANGING but it flickers really badly). I tried doing something by setting the bitmap to a GUICtrlCreatePic control but it still flickered. So essentially I need a way to create a graphics larger than the GUI itself and I don't know how to do something like that. I thought it would have been _GDIPlus_GraphicsCreateFromHDC but it still wasn't create it properly. I did a lot of googling and this topic has a lot of great info in it and I will probably incorporate scrollbars too, later, but UEZ didn't give the secret to resizing! Lol
      I've got the source code for vPaint downloaded, and I've started to through some of it (But like the author said, the source code is messy and things are out of order) so it may take a while.
       
      #include <GDIPlus.au3> #include <File.au3> #include <GUIConstants.au3> #include <String.au3> #include <GuiConstantsEx.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> #include <ScreenCapture.au3> #include <Color.au3> #include <Misc.au3> #include <WinAPISys.au3> #include <GuiToolbar.au3> #include <GuiImageList.au3> #include <Array.au3> AutoItSetOption("GuiOnEventMode", 1) AutoItSetOption("MustDeclareVars", 1) HotKeySet("{Esc}", "ClosePixShop") Global $frm_pixshop_abscoord[4] = [100, 100, 400, 200] Global $frmPixShop Global $tlbPixShopToolbar Global $hWnd_toolbar_image_list Global $hWnd_dll = DllOpen("user32.dll") Global $frm_pixshop_state = @SW_HIDE Global $hWnd_bitmaps[1] Global $picBitmaps[1] Global $abscoord_bitmaps[1][2] = [[0, 0]] Global $abscoord_graphics[4] = [8, 46, 0, 0] Global $pixshop_buffer[1] Global Enum $idToolbarStart = 1000, $idMouse, $idSnip, $idCrop, $idText, $idBrush, $idToolbarEnd Global $hWnd_pixshop_graphics Global $hWnd_pixshop_bitmap Global $hWnd_pixshop_buffer PixShop() Func PixShop() $frmPixShop = GUICreate("PixShop", $frm_pixshop_abscoord[2], $frm_pixshop_abscoord[3], $frm_pixshop_abscoord[0], $frm_pixshop_abscoord[1], $WS_SIZEBOX, $WS_EX_TOPMOST) $tlbPixShopToolbar = _GUICtrlToolbar_Create($frmPixShop, $TBSTYLE_TRANSPARENT) GUICtrlCreateLabel("", 0, 36, $frm_pixshop_abscoord[2], $frm_pixshop_abscoord[3], -1, $WS_EX_LAYERED) GUICtrlSetBkColor(-1, 0x0D0D0D) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKRIGHT + $GUI_DOCKBOTTOM) GUISetBkColor(0x535353, $frmPixShop) $hWnd_toolbar_image_list = _GUIImageList_Create(24, 24, 5, 5) _GUIImageList_AddIcon($hWnd_toolbar_image_list, @ScriptDir & "\Icons\Mouse.ico") _GUIImageList_AddIcon($hWnd_toolbar_image_list, @ScriptDir & "\Icons\Snip.ico") _GUIImageList_AddIcon($hWnd_toolbar_image_list, @ScriptDir & "\Icons\Crop.ico") _GUIImageList_AddIcon($hWnd_toolbar_image_list, @ScriptDir & "\Icons\Text.ico") _GUIImageList_AddIcon($hWnd_toolbar_image_list, @ScriptDir & "\Icons\Brush.ico") _GUICtrlToolbar_SetImageList($tlbPixShopToolbar, $hWnd_toolbar_image_list) _GUICtrlToolbar_SetIndent($tlbPixShopToolbar, 2) _GUICtrlToolbar_AddButton($tlbPixShopToolbar, $idMouse, 0) _GUICtrlToolbar_AddButton($tlbPixShopToolbar, $idSnip, 1) _GUICtrlToolbar_AddButton($tlbPixShopToolbar, $idCrop, 2) _GUICtrlToolbar_AddButton($tlbPixShopToolbar, $idText, 3) _GUICtrlToolbar_AddButton($tlbPixShopToolbar, $idBrush, 4) _GUICtrlToolbar_SetColorScheme($tlbPixShopToolbar, 0x535353, 0x535353) _GUICtrlToolbar_CheckButton($tlbPixShopToolbar, $idMouse, True) GUISetOnEvent($GUI_EVENT_CLOSE, "ClosePixShop") ; Register the WM_GETMINMAXINFO function GUIRegisterMsg($WM_GETMINMAXINFO, "WM_GETMINMAXINFO") ; Register the WM_NOTIFY function GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUIRegisterMsg($WM_WINDOWPOSCHANGING, "WM_WINDOWPOSCHANGING") GUIRegisterMsg($WM_PAINT, "WM_PAINT") GUISetState(@SW_SHOW, $frmPixShop) _GDIPlus_Startup() While (True) Sleep(100) WEnd EndFunc ;==>PixShop Func ClosePixShop() _GDIPlus_GraphicsDispose($hWnd_pixshop_graphics) _GDIPlus_BitmapDispose($hWnd_pixshop_bitmap) For $i = 0 To UBound($hWnd_bitmaps) - 1 _WinAPI_DeleteObject($hWnd_bitmaps[$i]) Next DllClose($hWnd_dll) Exit (0) EndFunc ;==>ClosePixShop Func WM_PAINT($hWndFrom, $iMsg, $wParam, $lParam) #forceref $hWndFrom, $iMsg, $wParam, $lParam DrawPixShopGraphics() EndFunc ;==>WM_PAINT Func WM_NOTIFY($hWndFrom, $iMsg, $wParam, $lParam) #forceref $hWndFrom, $iMsg, $wParam, $lParam Local $tNMTOOLBAR = DllStructCreate($tagNMTOOLBAR, $lParam) Local $tlbCode = DllStructGetData($tNMTOOLBAR, "Code") Local $iItem = DllStructGetData($tNMTOOLBAR, "iItem") Local $id_checked_button If ($tlbCode = $TBN_BEGINDRAG) Then If (Not _GUICtrlToolbar_IsButtonChecked($tlbPixShopToolbar, $iItem)) Then For $id = $idToolbarStart + 1 To $idToolbarEnd - 1 If (_GUICtrlToolbar_IsButtonChecked($tlbPixShopToolbar, $id)) Then $id_checked_button = $id _GUICtrlToolbar_CheckButton($tlbPixShopToolbar, $id, False) EndIf Next _GUICtrlToolbar_CheckButton($tlbPixShopToolbar, $iItem, True) EndIf Switch $iItem ; Button pressed was the $idColor button Case $idSnip Local $abscoord_frm_pixshop = WinGetPos($frmPixShop) While (_IsPressed("01", $hWnd_dll)) Sleep(10) WEnd GUISetState(@SW_HIDE, $frmPixShop) $hWnd_bitmaps[UBound($hWnd_bitmaps) - 1] = SnipArea($abscoord_bitmaps[UBound($abscoord_bitmaps, $UBOUND_ROWS) - 1][0], $abscoord_bitmaps[UBound($abscoord_bitmaps, $UBOUND_ROWS) - 1][1]) $pixshop_buffer[UBound($pixshop_buffer) - 1] = "SnippedImage|" & $hWnd_bitmaps[UBound($hWnd_bitmaps) - 1] ReDim $hWnd_bitmaps[UBound($hWnd_bitmaps)] ReDim $pixshop_buffer[UBound($pixshop_buffer)] If ($abscoord_graphics[2] = 0 And $abscoord_graphics[3] = 0) Then $abscoord_graphics[2] = $abscoord_bitmaps[UBound($abscoord_bitmaps, $UBOUND_ROWS) - 1][0] $abscoord_graphics[3] = $abscoord_bitmaps[UBound($abscoord_bitmaps, $UBOUND_ROWS) - 1][1] $pixshop_buffer[UBound($pixshop_buffer) - 1] = "ResizeGraphics|0,0-" & $abscoord_bitmaps[UBound($abscoord_bitmaps, $UBOUND_ROWS) - 1][0] & ',' & $abscoord_bitmaps[UBound($abscoord_bitmaps, $UBOUND_ROWS) - 1][1] ReDim $pixshop_buffer[UBound($pixshop_buffer)] #cs If (IsArray($abscoord_frm_pixshop)) Then If ($abscoord_frm_pixshop[2] < $abscoord_graphics[2]) Then WinMove($frmPixShop, "", $abscoord_frm_pixshop[0], $abscoord_frm_pixshop[1], $abscoord_graphics[2] + 24, $abscoord_frm_pixshop[3]) $abscoord_frm_pixshop[2] = $abscoord_graphics[2] + 24 EndIf If ($abscoord_frm_pixshop[3] < $abscoord_graphics[3]) Then WinMove($frmPixShop, "", $abscoord_frm_pixshop[0], $abscoord_frm_pixshop[1], $abscoord_frm_pixshop[2], $abscoord_graphics[3] + 46) $abscoord_frm_pixshop[3] = $abscoord_graphics[3] + 54 EndIf EndIf #ce EndIf ReDim $abscoord_bitmaps[UBound($abscoord_bitmaps, $UBOUND_ROWS)][2] GUISetState(@SW_SHOW, $frmPixShop) ResizePixShopGraphics() DrawPixShopGraphics() _GUICtrlToolbar_CheckButton($tlbPixShopToolbar, $iItem, False) _GUICtrlToolbar_CheckButton($tlbPixShopToolbar, $id_checked_button, True) Case $idCrop ToolTip("Crop Image") Case $idText ToolTip("Add Text") Case $idBrush ToolTip("Brush Image") EndSwitch EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func DrawPixShopGraphics() Local $hWnd_bitmap = _GDIPlus_BitmapCreateFromHBITMAP($hWnd_bitmaps[0]) _GDIPlus_GraphicsClear($hWnd_pixshop_buffer, 0x00000000) _GDIPlus_GraphicsDrawImageRect($hWnd_pixshop_buffer, $hWnd_bitmap, $abscoord_graphics[0], $abscoord_graphics[1], $abscoord_graphics[2], $abscoord_graphics[3]) _GDIPlus_ImageDispose($hWnd_bitmap) _GDIPlus_GraphicsDrawImage($hWnd_pixshop_graphics, $hWnd_pixshop_bitmap, 0, 0) EndFunc ;==>DrawPixShopGraphics Func SnipArea(ByRef $snipped_image_width, ByRef $snipped_image_height) Local $abscoord_mouse Local $hMask Local $hMaster_Mask Local $temp_val Local $mouse_x_1 Local $mouse_y_1 Local $mouse_x_2 Local $mouse_y_2 ToolTip("Left click and drag to select the area", 0, 0) Local $frmOverlay = GUICreate("GUI Overlay", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOPMOST) WinSetTrans($frmOverlay, "", 1) GUISetBkColor(0x000000, $frmOverlay) GUISetState(@SW_SHOW, $frmOverlay) GUISetCursor(3, 1, $frmOverlay) Local $frmSnipArea = GUICreate("GUI Snip", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST) GUISetBkColor(0xFF0000) ; Wait until mouse button pressed While (Not _IsPressed("01", $hWnd_dll)) Sleep(10) WEnd ; Get first mouse position $abscoord_mouse = MouseGetPos() $mouse_x_1 = $abscoord_mouse[0] $mouse_y_1 = $abscoord_mouse[1] ; Draw rectangle while mouse button pressed While _IsPressed("01", $hWnd_dll) $abscoord_mouse = MouseGetPos() $hMaster_Mask = _WinAPI_CreateRectRgn(0, 0, 0, 0) $hMask = _WinAPI_CreateRectRgn($mouse_x_1, $abscoord_mouse[1], $abscoord_mouse[0], $abscoord_mouse[1] + 1) ; Bottom of rectangle _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2) _WinAPI_DeleteObject($hMask) $hMask = _WinAPI_CreateRectRgn($mouse_x_1, $mouse_y_1, $mouse_x_1 + 1, $abscoord_mouse[1]) ; Left of rectangle _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2) _WinAPI_DeleteObject($hMask) $hMask = _WinAPI_CreateRectRgn($mouse_x_1 + 1, $mouse_y_1 + 1, $abscoord_mouse[0], $mouse_y_1) ; Top of rectangle _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2) _WinAPI_DeleteObject($hMask) $hMask = _WinAPI_CreateRectRgn($abscoord_mouse[0], $mouse_y_1, $abscoord_mouse[0] + 1, $abscoord_mouse[1]) ; Right of rectangle _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2) _WinAPI_DeleteObject($hMask) ; Set overall region _WinAPI_SetWindowRgn($frmSnipArea, $hMaster_Mask) If WinGetState($frmSnipArea) < 15 Then GUISetState() Sleep(10) WEnd ToolTip("") ; Get second mouse position $mouse_x_2 = $abscoord_mouse[0] $mouse_y_2 = $abscoord_mouse[1] ; Set in correct order if required If $mouse_x_2 < $mouse_x_1 Then $temp_val = $mouse_x_1 $mouse_x_1 = $mouse_x_2 $mouse_x_2 = $temp_val EndIf If $mouse_y_2 < $mouse_y_1 Then $temp_val = $mouse_y_1 $mouse_y_1 = $mouse_y_2 $mouse_y_2 = $temp_val EndIf GUIDelete($frmSnipArea) GUIDelete($frmOverlay) $snipped_image_width = $mouse_x_2 - $mouse_x_1 $snipped_image_height = $mouse_y_2 - $mouse_y_1 Return _ScreenCapture_Capture("", $mouse_x_1, $mouse_y_1, $mouse_x_2, $mouse_y_2, False) EndFunc ;==>SnipArea Func ResizePixShopGraphics() Local $graphics_width Local $graphics_height _GDIPlus_GraphicsDispose($hWnd_pixshop_graphics) _GDIPlus_BitmapDispose($hWnd_pixshop_bitmap) For $i = 0 To UBound($abscoord_bitmaps, $UBOUND_ROWS) - 1 $graphics_width += $abscoord_bitmaps[$i][0] $graphics_height += $abscoord_bitmaps[$i][1] Next $hWnd_pixshop_graphics = _GDIPlus_GraphicsCreateFromHWND($frmPixShop) $hWnd_pixshop_bitmap = _GDIPlus_BitmapCreateFromGraphics($graphics_width, $graphics_height, $hWnd_pixshop_graphics) $hWnd_pixshop_buffer = _GDIPlus_ImageGetGraphicsContext($hWnd_pixshop_bitmap) _GDIPlus_GraphicsSetSmoothingMode($hWnd_pixshop_buffer, $GDIP_SMOOTHINGMODE_HIGHQUALITY) _GDIPlus_GraphicsSetTextRenderingHint($hWnd_pixshop_graphics, $GDIP_TEXTRENDERINGHINT_ANTIALIASGRIDFIT) EndFunc ;==>ResizePixShopGraphics Func WM_WINDOWPOSCHANGING($hWndFrom, $iMsg, $wParam, $lParam) #forceref $hWndFrom, $iMsg, $wParam, $lParam If ($hWndFrom <> $frmPixShop) Then Return $GUI_RUNDEFMSG Local $stWinPos = DllStructCreate("uint;uint;int;int;int;int;uint", $lParam) Local $iLeft = DllStructGetData($stWinPos, 3) Local $iTop = DllStructGetData($stWinPos, 4) Local $iWidth = DllStructGetData($stWinPos, 5) Local $iHeight = DllStructGetData($stWinPos, 6) ResizePixShopGraphics() DrawPixShopGraphics() Return $GUI_RUNDEFMSG EndFunc ;==>WM_WINDOWPOSCHANGING Func WM_GETMINMAXINFO($hWndFrom, $iMsg, $wParam, $lParam) #forceref $hWndFrom, $iMsg, $wParam, $lParam Local $tagMaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam) DllStructSetData($tagMaxinfo, 7, 300) ; Set MIN width DllStructSetData($tagMaxinfo, 8, 200) ; Set MIN height Return $GUI_RUNDEFMSG EndFunc ;==>WM_GETMINMAXINFO
    • wolf9228
      By wolf9228
      Project to search for binary data in three different ways using assembly language

      Three ways

      - Search for a binary
      - Search for a binary using the callback function
      - Search for a binary using the data structure

      Find very fast .. Greetings
      Project Files
       ASM_BinarySearch.zip
       
      ASM_BinarySearch.au3
      #include <WinAPI.au3> Global $MsvcrtDll = _WinAPI_LoadLibrary( "msvcrt.dll" ) Global $Mmove = _WinAPI_GetProcAddress($MsvcrtDll,"memmove") Global $Malloc = _WinAPI_GetProcAddress($MsvcrtDll,"malloc") Global $FreeMemy = _WinAPI_GetProcAddress($MsvcrtDll,"free") Global $DwordSize=DllStructGetSize(DllStructCreate("DWORD")) Global $PointerSize=DllStructGetSize(DllStructCreate("PTR")) Global $AddressBinarySearch = LoadBinarySearch() Global $AddressBinarySearchPtr = DllStructGetPtr($AddressBinarySearch) Global $AddressCallbackBinarySearch = LoadCallbackBinarySearch() Global $AddressCallbackBinarySearchPtr = DllStructGetPtr($AddressCallbackBinarySearch) Global $AddressXBinarySearch = LoadXBinarySearch() Global $AddressXBinarySearchPtr = DllStructGetPtr($AddressXBinarySearch) Func BinarySearch($DataPtr,$SubDataPtr,$DataPtrSize,$SubDataPtrSize,$Step = 1) ; $Step Loop Step if ($SubDataPtrSize < 1) Or ($DataPtrSize < 1) Or ($SubDataPtrSize > $DataPtrSize) Then Return SetError(1,0,0) Local $MaxPosition = ($DataPtrSize - $SubDataPtrSize) $Return = DllCallAddress("DWORD",$AddressBinarySearchPtr,"DWORD",$MaxPosition, _ "DWORD",$DataPtrSize,"DWORD",$SubDataPtrSize,"PTR",$DataPtr,"PTR",$SubDataPtr,"DWORD",$Step) if @error Then Return SetError(2,0,0) Return $Return[0] ; Return FindPosition // OffSetPosition = FindPosition - 1 EndFunc Func CallbackBinarySearch($DataPtr,$SubDataPtr,$CbFuncName,$DataPtrSize,$SubDataPtrSize,$Step = 1) ; $Step Loop Step ;$CbFuncName ;Func CallbackFunc($FindPosition,$OffSetPosition,$DataPtr,$SubDataPtr,$DataPtrSize,$SubDataPtrSize) ;MsgBox(0,"OffSetPosition = " & $OffSetPosition ,"FindPosition = " & $FindPosition) ;Return 1 ;return ;0 ; Stop ;Other Ways : Continue ;EndFunc if ($SubDataPtrSize < 1) Or ($DataPtrSize < 1) Or ($SubDataPtrSize > $DataPtrSize) Then Return SetError(1,0,False) Local $RegCallbackFunc = DllCallbackRegister($CbFuncName,"DWORD","DWORD;DWORD;PTR;PTR;DWORD;DWORD") if @error Then Return SetError(2,0,False) Local $CkFuncPtr = DllCallbackGetPtr($RegCallbackFunc) Local $MaxPosition = ($DataPtrSize - $SubDataPtrSize) Local $StepTest = $Step >= $SubDataPtrSize $Return = DllCallAddress("DWORD",$AddressCallbackBinarySearchPtr,"DWORD",$MaxPosition,"DWORD", _ $DataPtrSize,"DWORD",$SubDataPtrSize,"PTR",$DataPtr,"PTR",$SubDataPtr,"PTR",$CkFuncPtr,"DWORD",$Step,"DWORD",$StepTest) if @error Then DllCallbackFree($RegCallbackFunc) Return SetError(3,0,False) EndIf DllCallbackFree($RegCallbackFunc) Return True ; Return BOOL EndFunc Func XBinarySearch($DataPtr,$SubDataPtr,$DataPtrSize,$SubDataPtrSize,$Step = 1) ; $Step Loop Step if ($SubDataPtrSize < 1) Or ($DataPtrSize < 1) Or ($SubDataPtrSize > $DataPtrSize) Then Return SetError(1,0,False) Local $tagReturnStruct = "DWORD ArrayCount;PTR PositionArray" Local $ReturnStruct = DllStructCreate($tagReturnStruct) Local $RtStructPtr = DllStructGetPtr($ReturnStruct) Local $MaxPosition = ($DataPtrSize - $SubDataPtrSize) Local $StepTest = $Step >= $SubDataPtrSize Local $Return = DllCallAddress("DWORD",$AddressXBinarySearchPtr,"DWORD",$MaxPosition,"DWORD",$DataPtrSize, _ "DWORD",$SubDataPtrSize,"PTR",$DataPtr,"PTR",$SubDataPtr,"PTR",$RtStructPtr,"DWORD",$Step,"DWORD",$StepTest) if @error Then Return SetError(2,0,0) Local $ArrayCount = DllStructGetData($ReturnStruct,1) Local $PosonArray = DllStructGetData($ReturnStruct,2) if ($ArrayCount = 0) Then Return SetError(3,0,0) Local $tagReturnStruct = "DWORD ArrayCount;DWORD PositionArray[" & $ArrayCount & "]" Local $ReturnStruct = DllStructCreate($tagReturnStruct) Local $NewPosonArray = DllStructGetPtr($ReturnStruct,2) DllStructSetData($ReturnStruct,1,$ArrayCount) DllCallAddress("ptr:cdecl",$Mmove,"ptr",$NewPosonArray,"ptr",$PosonArray,"int",($ArrayCount * $DwordSize)) DllCallAddress("none:cdecl",$FreeMemy,"ptr",$PosonArray) Return $ReturnStruct ; Return Struct of FindPosition // tagStruct = "DWORD ArrayCount;DWORD PositionArray[" & ArrayCount & "]" EndFunc Func LoadBinarySearch() Local $TA,$TB,$TC,$Start,$JGEnd,$JZTC,$TBJNZ,$JMPTA,$JMPStart,$End Local $OffSetMaxPosition = $PointerSize Local $OffSetDataPtrSize = ($OffSetMaxPosition + $DwordSize) Local $OffSetSubDataPtrSize = ($OffSetDataPtrSize + $DwordSize) Local $OffSetDataPtr = ($OffSetSubDataPtrSize + $DwordSize) Local $OffSetSubDataPtr = ($OffSetDataPtr + $PointerSize) Local $OffSetStep = ($OffSetSubDataPtr + $PointerSize) For $i = 1 To 2 $_ASMCode = "0x" $_ASMCode &= "BF" & HexBinary(0) ;mov edi,0 $_ASMCode &= "8B7424" & Hex($OffSetSubDataPtrSize,2) ;mov esi,[esp + $OffSetSubDataPtrSize] $_ASMCode &= "8B5C24" & Hex($OffSetDataPtr,2) ;mov ebx,[esp + $OffSetDataPtr] $_ASMCode &= "8B4424" & Hex($OffSetSubDataPtr,2) ;mov eax,[esp + $OffSetSubDataPtr] ; $Start: // $Start = BinaryLen($_ASMCode) $_ASMCode &= "BA" & HexBinary(0) ;mov edx,0 ; TA: // $TA = BinaryLen($_ASMCode) $_ASMCode &= "3BF2";CMP esi,edx $_ASMCode &= "74" & Hex(($TC - $JZTC),2) ;JZ $TC; $JZTC = BinaryLen($_ASMCode) $_ASMCode &= "8A2C10" ;mov CH,[eax + edx]; $_ASMCode &= "3A2C13" ;CMP CH,[ebx + edx] $_ASMCode &= "75" & Hex(($TB - $TBJNZ),2) ;JNZ TB $TBJNZ = BinaryLen($_ASMCode) $_ASMCode &= "83C2" & Hex(1,2) ;add edx,1 $JMPTA = BinaryLen($_ASMCode) $_ASMCode &= "E9" & HexBinary(-(($JMPTA - $TA) + 5)) ;JMP TA ; TB: // $TB = BinaryLen($_ASMCode) $_ASMCode &= "037C24" & Hex($OffSetStep,2) ;add edi,[esp + $OffSetStep] $_ASMCode &= "3B7C24" & Hex($OffSetMaxPosition,2) ;CMP edi,[esp + $OffSetMaxPosition] $_ASMCode &= "7F" & Hex(($End - $JGEnd),2) ;JG End $JGEnd = BinaryLen($_ASMCode) $_ASMCode &= "035C24" & Hex($OffSetStep,2) ;add ebx,[esp + $OffSetStep] $JMPStart = BinaryLen($_ASMCode) $_ASMCode &= "E9" & HexBinary(-(($JMPStart - $Start) + 5)) ;JMP Start ; TC: // $TC = BinaryLen($_ASMCode) $_ASMCode &= "83C7" & Hex(1,2) ;add edi,1 $_ASMCode &= "8BC7" ;mov eax,edi $_ASMCode &= "C2" & Hex((($PointerSize * 2) + ($DwordSize * 4)),2) & Hex(0,2) ;ret (($PointerSize * 2) + ($DwordSize * 3)) & "00" // Args Size ; End: // $End = BinaryLen($_ASMCode) $_ASMCode &= "B8" & HexBinary(0) ;mov eax,0 $_ASMCode &= "C2" & Hex((($PointerSize * 2) + ($DwordSize * 4)),2) & Hex(0,2) ;ret (($PointerSize * 2) + ($DwordSize * 3)) & "00" // Args Size Next $Address = DllStructCreate("byte[" & BinaryLen($_ASMCode) & "]") DllStructSetData($Address,1,$_ASMCode) Return $Address EndFunc Func LoadCallbackBinarySearch() Local $TA,$TB,$TC,$Start,$JGEnd,$JZTC,$TBJNZ,$JMPTA,$JMPStartA,$JMPStartB,$End,$JZEnd,$JGEnd2,$JZTD,$TD,$JGEnd3,$JMPStartC Local $OffSetMaxPosition = $PointerSize Local $OffSetDataPtrSize = ($OffSetMaxPosition + $DwordSize) Local $OffSetSubDataPtrSize = ($OffSetDataPtrSize + $DwordSize) Local $OffSetDataPtr = ($OffSetSubDataPtrSize + $DwordSize) Local $OffSetSubDataPtr = ($OffSetDataPtr + $PointerSize) Local $OffSetCkFuncPtr = ($OffSetSubDataPtr + $PointerSize) Local $OffSetStep = ($OffSetCkFuncPtr + $PointerSize) Local $OffSetStepTest = ($OffSetStep + $DwordSize) For $i = 1 To 2 $_ASMCode = "0x" $_ASMCode &= "BF" & HexBinary(0) ;mov edi,0 $_ASMCode &= "8B7424" & Hex($OffSetMaxPosition,2) ;mov esi,[esp + $OffSetMaxPosition] $_ASMCode &= "8B5C24" & Hex($OffSetDataPtr,2) ;mov ebx,[esp + $OffSetDataPtr] $_ASMCode &= "8B4C24" & Hex($OffSetSubDataPtr,2) ;mov ecx,[esp + $OffSetSubDataPtr] ; $Start: // $Start = BinaryLen($_ASMCode) $_ASMCode &= "BA" & HexBinary(0) ;mov edx,0 ; TA: // $TA = BinaryLen($_ASMCode) $_ASMCode &= "3B5424" & Hex($OffSetSubDataPtrSize,2) ;CMP edx,[esp + $OffSetSubDataPtrSize] $_ASMCode &= "74" & Hex(($TC - $JZTC),2) ;JZ $TC; $JZTC = BinaryLen($_ASMCode) $_ASMCode &= "8A2413" ;mov AH,[ebx + edx] $_ASMCode &= "3A2411" ;CMP AH,[ecx + edx] $_ASMCode &= "75" & Hex(($TB - $TBJNZ),2) ;JNZ TB $TBJNZ = BinaryLen($_ASMCode) $_ASMCode &= "83C2" & Hex(1,2) ;add edx,1 $JMPTA = BinaryLen($_ASMCode) $_ASMCode &= "E9" & HexBinary(-(($JMPTA - $TA) + 5)) ;JMP TA ; TB: // $TB = BinaryLen($_ASMCode) $_ASMCode &= "037C24" & Hex($OffSetStep,2) ;add edi,[esp + $OffSetStep] $_ASMCode &= "3BFE" ;CMP edi,esi $_ASMCode &= "7F" & Hex(($End - $JGEnd),2) ;JG End $JGEnd = BinaryLen($_ASMCode) $_ASMCode &= "035C24" & Hex($OffSetStep,2) ;add ebx,[esp + $OffSetStep] $JMPStartA = BinaryLen($_ASMCode) $_ASMCode &= "E9" & HexBinary(-(($JMPStartA - $Start) + 5)) ;JMP Start ; TC: // $TC = BinaryLen($_ASMCode) $_ASMCode &= "8B4424" & Hex($OffSetCkFuncPtr,2) ;mov eax,[esp + $OffSetCkFuncPtr] $_ASMCode &= "FF7424" & Hex($OffSetSubDataPtrSize,2) ;push [esp + $OffSetSubDataPtrSize] $_ASMCode &= "FF7424" & Hex($OffSetDataPtrSize,2) ;push [esp + $OffSetDataPtrSize] $_ASMCode &= "FF7424" & Hex($OffSetSubDataPtr,2) ;push [esp + $OffSetSubDataPtr] $_ASMCode &= "FF7424" & Hex($OffSetDataPtr,2) ;push [esp + $OffSetDataPtr] $_ASMCode &= "57" ;push edi; $_ASMCode &= "83C7" & Hex(1,2) ;add edi,1 $_ASMCode &= "57" ;push edi; $_ASMCode &= "83EF" & Hex(1,2) ;sub edi,1 $_ASMCode &= "FFD0" ;call eax $_ASMCode &= "83F8" & Hex(0,2);CMP eax,0 $_ASMCode &= "74" & Hex(($End - $JZEnd),2) ;JZ $End; $JZEnd = BinaryLen($_ASMCode) $_ASMCode &= "8B4424" & Hex($OffSetStepTest,2) ;mov eax,[esp + $OffSetStepTest] $_ASMCode &= "83F8" & Hex(1,2);CMP eax,1 $_ASMCode &= "74" & Hex(($TD - $JZTD),2) ;JZ $TD; $JZTD = BinaryLen($_ASMCode) $_ASMCode &= "037C24" & Hex($OffSetSubDataPtrSize,2) ;add edi,[esp + $OffSetSubDataPtrSize] $_ASMCode &= "3BFE" ;CMP edi,esi $_ASMCode &= "7F" & Hex(($End - $JGEnd3),2) ;JG End $JGEnd3 = BinaryLen($_ASMCode) $_ASMCode &= "035C24" & Hex($OffSetSubDataPtrSize,2) ;add ebx,[esp + $OffSetSubDataPtrSize] $_ASMCode &= "8B4C24" & Hex($OffSetSubDataPtr,2) ;mov ecx,[esp + $OffSetSubDataPtr] $JMPStartC = BinaryLen($_ASMCode) $_ASMCode &= "E9" & HexBinary(-(($JMPStartC - $Start) + 5)) ;JMP Start ; TD: // $TD = BinaryLen($_ASMCode) $_ASMCode &= "037C24" & Hex($OffSetStep,2) ;add edi,[esp + $OffSetStep] $_ASMCode &= "3BFE" ;CMP edi,esi $_ASMCode &= "7F" & Hex(($End - $JGEnd2),2) ;JG End $JGEnd2 = BinaryLen($_ASMCode) $_ASMCode &= "035C24" & Hex($OffSetStep,2) ;add ebx,[esp + $OffSetStep] $_ASMCode &= "8B4C24" & Hex($OffSetSubDataPtr,2) ;mov ecx,[esp + $OffSetSubDataPtr] $JMPStartB = BinaryLen($_ASMCode) $_ASMCode &= "E9" & HexBinary(-(($JMPStartB - $Start) + 5)) ;JMP Start ; End: // $End = BinaryLen($_ASMCode) $_ASMCode &= "B8" & HexBinary(0) ;mov eax,0 $_ASMCode &= "C2" & Hex((($PointerSize * 3) + ($DwordSize * 5)),2) & Hex(0,2) ;ret (($PointerSize * 3) + ($DwordSize * 5)) & "00" // Args Size Next $Address = DllStructCreate("byte[" & BinaryLen($_ASMCode) & "]") DllStructSetData($Address,1,$_ASMCode) Return $Address EndFunc Func LoadXBinarySearch() Local $TA,$TB,$TC,$TD,$Start,$JGEnd,$JZTC,$TBJNZ,$JMPTA,$JMPStartA,$JMPStartB Local $JMPStartC ,$End,$JZEnd,$JZTD,$TE,$JZTE,$JMPStartD,$TF,$JZTF,$JMPStartE Local $OffSetMaxPosition = $PointerSize Local $OffSetDataPtrSize = ($OffSetMaxPosition + $DwordSize) Local $OffSetSubDataPtrSize = ($OffSetDataPtrSize + $DwordSize) Local $OffSetDataPtr = ($OffSetSubDataPtrSize + $DwordSize) Local $OffSetSubDataPtr = ($OffSetDataPtr + $PointerSize) Local $OffSetRtStPtr = ($OffSetSubDataPtr + $PointerSize) Local $OffSetStep = ($OffSetRtStPtr + $PointerSize) Local $OffSetStepTest = ($OffSetStep + $DwordSize) For $i = 1 To 2 $_ASMCode = "0x" $_ASMCode &= "BF" & HexBinary(0) ;mov edi,0 ;$Start: // $Start = BinaryLen($_ASMCode) $_ASMCode &= "8B4424" & Hex($OffSetMaxPosition,2) ;mov eax,[esp + $OffSetMaxPosition] $_ASMCode &= "3BF8" ;CMP edi,eax $_ASMCode &= "0F8F" & HexBinary(($End - $JGEnd)) ;JG End $JGEnd = BinaryLen($_ASMCode) $_ASMCode &= "BE" & HexBinary(0) ;mov esi,0 ; TA: // $TA = BinaryLen($_ASMCode) $_ASMCode &= "8B4424" & Hex($OffSetSubDataPtrSize,2) ;mov eax,[esp + $OffSetSubDataPtrSize] $_ASMCode &= "3BF0" ;CMP esi,eax $_ASMCode &= "74" & Hex(($TC - $JZTC),2) ;JZ $TC; $JZTC = BinaryLen($_ASMCode) $_ASMCode &= "8B5C24" & Hex($OffSetDataPtr,2) ;mov ebx,[esp + $OffSetDataPtr] $_ASMCode &= "03DF" ;add ebx,edi $_ASMCode &= "03DE" ;add ebx,esi $_ASMCode &= "8A0B" ;mov CL,[ebx]; $_ASMCode &= "8B5C24" & Hex($OffSetSubDataPtr,2) ;mov ebx,[esp + $OffSetSubDataPtr] $_ASMCode &= "03DE" ;add ebx,esi $_ASMCode &= "8A2B" ;mov CH,[ebx]; $_ASMCode &= "3ACD" ;CMP CL,CH $_ASMCode &= "75" & Hex(($TB - $TBJNZ),2) ;JNZ TE $TBJNZ = BinaryLen($_ASMCode) $_ASMCode &= "83C6" & Hex(1,2) ;add esi,1 $JMPTA = BinaryLen($_ASMCode) $_ASMCode &= "E9" & HexBinary(-(($JMPTA - $TA) + 5)) ;JMP TA ; TB: // $TB = BinaryLen($_ASMCode) $_ASMCode &= "037C24" & Hex($OffSetStep,2) ;add edi,[esp + $OffSetStep] $JMPStartA = BinaryLen($_ASMCode) $_ASMCode &= "E9" & HexBinary(-(($JMPStartA - $Start) + 5)) ;JMP Start ; TC: // $TC = BinaryLen($_ASMCode) $_ASMCode &= "8B4424" & Hex($OffSetRtStPtr,2) ;mov eax,[esp + $OffSetRtStPtr] $_ASMCode &= "8B00" ;mov eax,[eax] $_ASMCode &= "83F8" & Hex(0,2);CMP eax,0 $_ASMCode &= "74" & Hex(($TD - $JZTD),2) ;JZ $TD $JZTG = BinaryLen($_ASMCode) $_ASMCode &= "83C7" & Hex(1,2) ;add edi,1 $_ASMCode &= "8B4424" & Hex($OffSetRtStPtr,2) ;mov eax,[esp + $OffSetRtStPtr] $_ASMCode &= "8B00" ;mov eax,[eax] $_ASMCode &= "83C0" & Hex(1,2) ;add eax,1 $_ASMCode &= "B9" & HexBinary($DwordSize) ;mov ecx,$DwordSize $_ASMCode &= "F7E1" ;MUL ecx; $_ASMCode &= "50" ;push eax $_ASMCode &= "B8" & HexBinary($Malloc) ;mov eax,$Malloc $_ASMCode &= "FFD0" ;call eax $_ASMCode &= "83C4" & Hex($DwordSize,2) ;add esp,$DwordSize $_ASMCode &= "8BD8" ;mov ebx,eax $_ASMCode &= "8B4424" & Hex($OffSetRtStPtr,2) ;mov eax,[esp + $OffSetRtStPtr] $_ASMCode &= "8B00" ;mov eax,[eax] $_ASMCode &= "B9" & HexBinary($DwordSize) ;mov ecx,$DwordSize $_ASMCode &= "F7E1" ;MUL ecx; $_ASMCode &= "50" ;push eax $_ASMCode &= "8B4424" & Hex(($OffSetRtStPtr + $DwordSize),2) ;mov eax,[esp + ($OffSetRtStPtr + $DwordSize)] $_ASMCode &= "83C0" & Hex($DwordSize,2) ;add eax,$DwordSize $_ASMCode &= "8B00" ;mov eax,[eax] $_ASMCode &= "50" ;push eax $_ASMCode &= "53" ;push ebx $_ASMCode &= "B8" & HexBinary($Mmove) ;mov eax,$Mmove $_ASMCode &= "FFD0" ;call eax $_ASMCode &= "83C4" & Hex((($PointerSize * 2) + $DwordSize),2) ;add esp,(($PointerSize * 2) + $DwordSize) $_ASMCode &= "8B4424" & Hex($OffSetRtStPtr,2) ;mov eax,[esp + $OffSetRtStPtr] $_ASMCode &= "83C0" & Hex($DwordSize,2) ;add eax,$DwordSize $_ASMCode &= "8B00" ;mov eax,[eax] $_ASMCode &= "50" ;push eax $_ASMCode &= "B8" & HexBinary($FreeMemy) ;mov eax,$FreeMemy $_ASMCode &= "FFD0" ;call eax $_ASMCode &= "83C4" & Hex($PointerSize,2) ;add esp,$PointerSize $_ASMCode &= "8B4424" & Hex($OffSetRtStPtr,2) ;mov eax,[esp + $OffSetRtStPtr] $_ASMCode &= "8B00" ;mov eax,[eax] $_ASMCode &= "B9" & HexBinary($DwordSize) ;mov ecx,$DwordSize $_ASMCode &= "F7E1" ;MUL ecx; $_ASMCode &= "893C03" ;mov [ebx + eax],edi $_ASMCode &= "8B4424" & Hex($OffSetRtStPtr,2) ;mov eax,[esp + $OffSetRtStPtr] $_ASMCode &= "8000" & Hex(1,2) ;add [eax],1 $_ASMCode &= "83C0" & Hex($DwordSize,2) ;add eax,$DwordSize $_ASMCode &= "8918" ;mov [eax],ebx $_ASMCode &= "83EF" & Hex(1,2) ;sub edi,1 $_ASMCode &= "8B4424" & Hex($OffSetStepTest,2) ;mov eax,[esp + $OffSetStepTest] $_ASMCode &= "83F8" & Hex(1,2);CMP eax,1 $_ASMCode &= "74" & Hex(($TF - $JZTF),2) ;JZ $TF; $JZTF = BinaryLen($_ASMCode) $_ASMCode &= "037C24" & Hex($OffSetSubDataPtrSize,2) ;add edi,[esp + $OffSetSubDataPtrSize] $JMPStartE = BinaryLen($_ASMCode) $_ASMCode &= "E9" & HexBinary(-(($JMPStartE - $Start) + 5)) ;JMP Start ; TF: // $TF = BinaryLen($_ASMCode) $_ASMCode &= "037C24" & Hex($OffSetStep,2) ;add edi,[esp + $OffSetStep] $JMPStartB = BinaryLen($_ASMCode) $_ASMCode &= "E9" & HexBinary(-(($JMPStartB - $Start) + 5)) ;JMP Start ; $TD: // $TD = BinaryLen($_ASMCode) $_ASMCode &= "83C7" & Hex(1,2) ;add edi,1 $_ASMCode &= "BB" & HexBinary($DwordSize) ;mov ebx,$DwordSize $_ASMCode &= "53" ;push ebx $_ASMCode &= "B8" & HexBinary($Malloc) ;mov eax,$Malloc $_ASMCode &= "FFD0" ;call eax $_ASMCode &= "83C4" & Hex($DwordSize,2) ;add esp,$DwordSize $_ASMCode &= "8938" ;mov [eax],edi $_ASMCode &= "8B5C24" & Hex($OffSetRtStPtr,2) ;mov ebx,[esp + $OffSetRtStPtr] $_ASMCode &= "C603" & Hex(1,2) ;mov [ebx],1 $_ASMCode &= "83C3" & Hex($DwordSize,2) ;add ebx,$DwordSize $_ASMCode &= "8903" ;mov [ebx],eax $_ASMCode &= "83EF" & Hex(1,2) ;sub edi,1 $_ASMCode &= "8B4424" & Hex($OffSetStepTest,2) ;mov eax,[esp + $OffSetStepTest] $_ASMCode &= "83F8" & Hex(1,2);CMP eax,1 $_ASMCode &= "74" & Hex(($TE - $JZTE),2) ;JZ $TE; $JZTE = BinaryLen($_ASMCode) $_ASMCode &= "037C24" & Hex($OffSetSubDataPtrSize,2) ;add edi,[esp + $OffSetSubDataPtrSize] $JMPStartD = BinaryLen($_ASMCode) $_ASMCode &= "E9" & HexBinary(-(($JMPStartD - $Start) + 5)) ;JMP Start ; $TE: // $TE = BinaryLen($_ASMCode) $_ASMCode &= "037C24" & Hex($OffSetStep,2) ;add edi,[esp + $OffSetStep] $JMPStartC = BinaryLen($_ASMCode) $_ASMCode &= "E9" & HexBinary(-(($JMPStartC - $Start) + 5)) ;JMP Start ; End: // $End = BinaryLen($_ASMCode) $_ASMCode &= "B8" & HexBinary(0) ;mov eax,0 $_ASMCode &= "C2" & Hex((($PointerSize * 3) + ($DwordSize * 5)),2) & Hex(0,2) ;ret (($PointerSize * 3) + ($DwordSize * 3)) & "00" // Args Size Next $Address = DllStructCreate("byte[" & BinaryLen($_ASMCode) & "]") DllStructSetData($Address,1,$_ASMCode) Return $Address EndFunc Func HexBinary($Value) Return Hex(Binary($Value)) EndFunc  
      ColorSearch.au3
      #include <WinAPI.au3> #include <Memory.au3> #include <Color.au3> #include <ScreenCapture.au3> #include "ASM_BinarySearch.au3" Global $itagRGBQUAD = "BYTE rgbBlue;BYTE rgbGreen;BYTE rgbRed;BYTE rgbReserved" Global $RgbSize = DllStructGetSize(DllStructCreate($itagRGBQUAD)) $hGUI = GUICreate("Color Gui",20,20,@DesktopWidth - 20,@DesktopHeight - 100) GUISetBkColor(0xFF80FF, $hGUI) GUISetState(@SW_SHOW, $hGUI) MsgBox(0,"PixelSearch","PixelSearch") $hTimer = TimerInit() $Pos1 = PixelSearch(0 , 0, @DesktopWidth, @DesktopHeight,0xFF80FF) ;0xFFFFFF $iDiff1 = TimerDiff($hTimer) MsgBox(0,"nPixelSearch","nPixelSearch") $hTimer = TimerInit() $Pos2 = nPixelSearch(0, 0, @DesktopWidth, @DesktopHeight,0xFF80FF) ;0xFFFFFF $iDiff2 = TimerDiff($hTimer) if IsArray($Pos1) And IsArray($Pos2) Then $Text1 = String($Pos1[0] & " " & $Pos1[1] & " PixelSearch Time ==> " & $iDiff1) $Text2 = String($Pos2[0] & " " & $Pos2[1] & " nPixelSearch Time ==> " & $iDiff2) MsgBox(0,"PixelSearch",$Text1 & @CRLF & $Text2) EndIf MsgBox(0,"nPixelSearch","nPixelSearch") $hTimer = TimerInit() $Pos2 = nPixelSearch(0, 0, @DesktopWidth, @DesktopHeight,0xFF80FF) ;0xFFFFFF $iDiff2 = TimerDiff($hTimer) MsgBox(0,"PixelSearch","PixelSearch") $hTimer = TimerInit() $Pos1 = PixelSearch(0 , 0, @DesktopWidth, @DesktopHeight,0xFF80FF) ;0xFFFFFF $iDiff1 = TimerDiff($hTimer) if IsArray($Pos1) And IsArray($Pos2) Then $Text1 = String($Pos1[0] & " " & $Pos1[1] & " PixelSearch Time ==> " & $iDiff1) $Text2 = String($Pos2[0] & " " & $Pos2[1] & " nPixelSearch Time ==> " & $iDiff2) MsgBox(0,"PixelSearch",$Text1 & @CRLF & $Text2) EndIf Func nPixelSearch($left = 0,$top = 0,$right = -1,$bottom = -1,$Color = 0,$bCursor = False) Local $hBmp = _ScreenCapture_Capture("",$left,$top,$right,$bottom,$bCursor) if Not($hBmp) Then Return SetError(1,0,0) Local $aCoord = BmpSearchColor($hBmp,$Color) _WinAPI_DeleteObject($hBmp) if Not IsArray($aCoord) Then Return SetError(2,0,0) Return $aCoord EndFunc Func BmpSearchColor($hBmp,$Color) Local $BitsStruct = GetBitsStruct($hBmp) if @error Then Return SetError(1,0,0) Local $BitsStringPtr = DllStructGetPtr($BitsStruct,"RGBQUAD") Local $BitsSize = DllStructGetData($BitsStruct,"SIZE") Local $biWidth = DllStructGetData($BitsStruct,"WIDTH") Local $biHeight = DllStructGetData($BitsStruct,"HEIGHT") Local $iColor = DllStructCreate("BYTE RGB[3]") DllStructSetData($iColor,1,$Color) $iColorPtr = DllStructGetPtr($iColor) $FindPosition = BinarySearch($BitsStringPtr,$iColorPtr,$BitsSize,3,4) ;$SubDataPtrSize = 3 // $Step = $RgbSize = 4 // ; $Step Is Loop Step if @error Then Return SetError(2,0,0) Local $OffSetPosition = $FindPosition - 1 $OffSetPosition /= $RgbSize ; $RgbSize = 4 /// 4byte = 1pixel $X = Mod($OffSetPosition,$biWidth) ; Get left $Y = (($OffSetPosition - $X) / $biWidth) ; Get top Local $aCoord[2] $aCoord[0] = $X $aCoord[1] = $Y Return $aCoord EndFunc Func GetBitsStruct( $hBmp , $L = -1 , $T = -1 , $W = -1 , $H = -1 ) Local $SizeArray = GetImageSize($hBmp) if @error Then Return SetError(1,0,0) Local $biWidth = $SizeArray[0] Local $biHeight = $SizeArray[1] if ($L < 0) Then $L = 0 if ($T < 0) Then $T = 0 if ($W < 0) Then $W = ($biWidth - $L) if ($H < 0) Then $H = ($biHeight - $T) if ($L >= $biWidth Or (($L + $W) > $biWidth)) Then $L = 0 if ($T >= $biHeight Or (($T + $H) > $biHeight)) Then $T = 0 Local $vRgbSize = ($RgbSize * ($biWidth * $biHeight)) Local $vStBits = DllStructCreate("INT WIDTH;INT HEIGHT;INT SIZE;BYTE RGBQUAD[" & ($vRgbSize) & "]") DllStructSetData($vStBits ,"WIDTH",$biWidth) DllStructSetData($vStBits,"HEIGHT",$biHeight) DllStructSetData($vStBits,"SIZE",$vRgbSize) GetBitmapBits($hBmp,DllStructGetPtr($vStBits,"RGBQUAD"),$vRgbSize) if @error Then Return SetError(2,0,0) if ($L = 0 And $T = 0 And $W = $biWidth And $H = $biHeight) Then Return $vStBits Local $nRgbSize = ($RgbSize * ($W * $H)) , $ColusCount = $W Local $nStBits = DllStructCreate("INT WIDTH;INT HEIGHT;INT SIZE;BYTE RGBQUAD[" & ($nRgbSize) & "]") DllStructSetData($nStBits ,"WIDTH",$W) DllStructSetData($nStBits,"HEIGHT",$H) DllStructSetData($nStBits,"SIZE",$nRgbSize) For $RowIndex = 0 To ($H - 1) Local $nStBPtr = GetPointerAtRowPos($nStBits,$RowIndex) ; Move Ptr To First BYTE Of Row => $RowIndex Local $vStBPtr = GetPointerAtRowPos($vStBits,($RowIndex + $T)) + ($L * $RgbSize) ; Move Ptr To First BYTE Of Row => ($RowIndex + $T) ; + ($L * $RgbSize) Move PointerAtRowPos From left to right + ($L * $RgbSize) _MemMoveMemory($vStBPtr,$nStBPtr,($RgbSize * ($ColusCount - 1))) ;Size Of One Row In $nStBPtr Next Return $nStBits EndFunc Func GetBitmapBits($hbmp,$lpvBits,$cbBuffer) $BytesNu = DllCall("Gdi32.dll","LONG","GetBitmapBits","ptr" _ ,$hbmp,"LONG",$cbBuffer,"ptr",$lpvBits) if @error Or Not($BytesNu[0]) Then SetError(1,0,0) Return SetError(0,0,$BytesNu[0]) EndFunc Func GetPointerAtRowPos($StBits,$RowIndex) if Not IsDllStruct($StBits) Then Return SetError(1,0,0) Local $ColusCount = DllStructGetData($StBits,"WIDTH") Local $RowsCount = DllStructGetData($StBits,"HEIGHT") If ($RowIndex < 0 Or $RowIndex > ($RowsCount -1)) Then Return SetError(2,0,0) Local $StBitsPtr = DllStructGetPtr($StBits,"RGBQUAD") Local $PointerAtRowPos = ($StBitsPtr + (($RowIndex * $ColusCount) * $RgbSize)) Return $PointerAtRowPos EndFunc Func GetImageSize($hBmp) Local $ntagBITMAPINFO = "DWORD biSize;LONG biWidth;LONG biHeight;USHORT biPlanes;" & _ "USHORT biBitCount;DWORD biCompression;DWORD biSizeImage;LONG biXPelsPerMeter;" & _ "LONG biYPelsPerMeter;DWORD biClrUsed;DWORD biClrImportant;BYTE RGBQUAD[4]" Local $vBITMAPINFO = DllStructCreate($ntagBITMAPINFO) DllStructSetData($vBITMAPINFO,"biSize",(DllStructGetSize($vBITMAPINFO) - $RgbSize)) Local $hDC = _WinAPI_CreateCompatibleDC(0) if Not($hDC) Then _WinAPI_DeleteDC($hDC) Return SetError(1,0,0) EndIf $Return = _WinAPI_GetDIBits($hDC,$hBmp,0,0,0,DllStructGetPtr($vBITMAPINFO),0) if Not($Return) Then _WinAPI_DeleteDC($hDC) Return SetError(2,0,0) EndIf _WinAPI_DeleteDC($hDC) Local $biWidth = DllStructGetData($vBITMAPINFO,"biWidth") Local $biHeight = DllStructGetData($vBITMAPINFO,"biHeight") Local $SizeArray[2] $SizeArray[0] = $biWidth $SizeArray[1] = $biHeight Return $SizeArray EndFunc CallbackBinarySearch.au3
      #include <WinAPI.au3> #include <Memory.au3> #include <Color.au3> #include <ScreenCapture.au3> #include "ASM_BinarySearch.au3" $Text = "" $SubText = "Autoit" For $i = 1 To 10000 $Text &= "1" Next $Text &= "Autoit" & "Autoit" & "Autoit" $Len1 = StringLen($Text) $Len2 = StringLen($SubText) $St1 = DllStructCreate("CHAR[" & $Len1 & "]") DllStructSetData($St1,1,$Text) $Ptr1 = DllStructGetPtr($St1) $St2 = DllStructCreate("CHAR[" & $Len2 & "]") DllStructSetData($St2,1,$SubText) $Ptr2 = DllStructGetPtr($St2) $Return = CallbackBinarySearch($Ptr1,$Ptr2,"CallbackFunc",$Len1,$Len2) MsgBox(0,"Return",$Return) Func CallbackFunc($FindPosition,$OffSetPosition,$DataPtr,$SubDataPtr,$DataPtrSize,$SubDataPtrSize) MsgBox(0,"OffSetPosition = " & $OffSetPosition ,"FindPosition = " & $FindPosition) Return 1 ;return ;0 ; Stop ;Other Ways : Continue EndFunc XBinarySearch.au3
      #include <WinAPI.au3> #include <Memory.au3> #include <Color.au3> #include <ScreenCapture.au3> #include "ASM_BinarySearch.au3" $Text = "" $SubText = "Autoit" For $i = 1 To 10000 $Text &= "1" Next $Text &= "Autoit" & "Autoit" & "Autoit" $Len1 = StringLen($Text) $Len2 = StringLen($SubText) $St1 = DllStructCreate("CHAR[" & $Len1 & "]") DllStructSetData($St1,1,$Text) $Ptr1 = DllStructGetPtr($St1) $St2 = DllStructCreate("CHAR[" & $Len2 & "]") DllStructSetData($St2,1,$SubText) $Ptr2 = DllStructGetPtr($St2) $ReturnStruct = XBinarySearch($Ptr1,$Ptr2,$Len1,$Len2) For $i = 1 To DllStructGetData($ReturnStruct,"ArrayCount") $FindPosition = DllStructGetData($ReturnStruct,"PositionArray",$i) MsgBox(0,"Msg","FindPosition = " & $FindPosition) Next  
×