Jump to content

Crop image search


Recommended Posts

Hello, I am rather new to Autoit and I'm looking for some tips and tricks. I wonder, is Autoit capable of reading croped images rather than croping? (I did use the search function best I can but found nothing of help) If so, could you be kind enough to give me an example of such a code or a how-to tutorial?

Best regards,

- Tf

Link to comment
Share on other sites

Here is how I crop an Image

#include <GDIPlus.au3>

_GDIPlus_Startup()

$hBmp = _GDIPlus_ImageLoadFromFile(StringReplace(@AutoItExe,"Autoit3.exe", "Examples\GUI\msoobe.jpg"))
_GDIPlus_CropImage($hBmp, 10, 10, 100, 100)
_GDIPlus_ImageSaveToFile($hBmp, @DesktopDir & "\Test.jpg")
ShellExecute(@DesktopDir & "\Test.jpg")

_GDIPlus_Shutdown()
Exit

Func _GDIPlus_CropImage(ByRef $hBmp, $iX, $iY, $iWidth, $iHeight)

    $h_Bmp_Ret = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight)
    $h_Bmp_Ret_Gfx = _GDIPlus_ImageGetGraphicsContext($h_Bmp_Ret)

    _GDIPlus_GraphicsDrawImageRectRect($h_Bmp_Ret_Gfx, $hBmp, $iX, $iY, $iWidth, $iHeight, 0, 0, $iWidth, $iHeight)

    _GDIPlus_GraphicsDispose($h_Bmp_Ret_Gfx)
    _GDIPlus_ImageDispose($hBmp)
    $hBmp = $h_Bmp_Ret
    $h_Bmp_Ret = 0

EndFunc   ;==>_GDIPlus_CropImage

Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0)

    If @error Then Return SetError(@error, @extended, 0)
    $GDIP_STATUS = $aResult[0]
    Return $aResult[6]
EndFunc   ;==>_GDIPlus_BitmapCreateFromScan0

What do you mean by reading cropped image ?

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

@PhoenixXL: cropping can be done easily using

 

_GDIPlus_BitmapCloneArea() 

Br,

UEZ

Edited by UEZ

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

Selection of finest graphical examples at Codepen.io

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

Link to comment
Share on other sites

_GDIPlus_BitmapCloneArea()  

Thanks UEZ.  :oops:

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

Here is how I crop an Image

#include <GDIPlus.au3>

_GDIPlus_Startup()

$hBmp = _GDIPlus_ImageLoadFromFile(StringReplace(@AutoItExe,"Autoit3.exe", "Examples\GUI\msoobe.jpg"))
_GDIPlus_CropImage($hBmp, 10, 10, 100, 100)
_GDIPlus_ImageSaveToFile($hBmp, @DesktopDir & "\Test.jpg")
ShellExecute(@DesktopDir & "\Test.jpg")

_GDIPlus_Shutdown()
Exit

Func _GDIPlus_CropImage(ByRef $hBmp, $iX, $iY, $iWidth, $iHeight)

    $h_Bmp_Ret = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight)
    $h_Bmp_Ret_Gfx = _GDIPlus_ImageGetGraphicsContext($h_Bmp_Ret)

    _GDIPlus_GraphicsDrawImageRectRect($h_Bmp_Ret_Gfx, $hBmp, $iX, $iY, $iWidth, $iHeight, 0, 0, $iWidth, $iHeight)

    _GDIPlus_GraphicsDispose($h_Bmp_Ret_Gfx)
    _GDIPlus_ImageDispose($hBmp)
    $hBmp = $h_Bmp_Ret
    $h_Bmp_Ret = 0

EndFunc   ;==>_GDIPlus_CropImage

Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0)

    If @error Then Return SetError(@error, @extended, 0)
    $GDIP_STATUS = $aResult[0]
    Return $aResult[6]
EndFunc   ;==>_GDIPlus_BitmapCreateFromScan0

What do you mean by reading cropped image ?

Thanks for your response(s)

What I mean by reading a cropped image is; instead of doing pixel reading it reads the cropped image, lets say i want to leave the program on while i sleep to scan for fluctuations (I guess you can call them?) which is bigger than a few pixels and of several colours. I hope you understand what I mean.

I am slightly confused about this myself but I want to learn! Preferably by good tutorials, or other means.

Edit: If cropped image is found; playsound C:/Bleh.wmp (Or save timestamp when found)

 
Edited by Tenderfoot
Link to comment
Share on other sites

Do you want this

; #FUNCTION# ====================================================================================================================
; Name...........: _GDIPlus_BitmapGetPixel
; Description ...: Gets the color of a specified pixel in this bitmap
; Syntax.........: _GDIPlus_BitmapGetPixel($hBitmap, $iX, $iY)
; Parameters ....: $hBitmap - Pointer to the Bitmap object
;                  $iX      - The X coordinate of the pixel
;                  $iY      - The Y coordinate of the pixel
; Return values .: Success      - Returns the pixel color of the bitmap
;                  Failure      - 0 and either:
;                  |@error and @extended are set if DllCall failed
;                  |$GDIP_STATUS contains a non zero value specifying the error code
; Remarks .......: None
; Related .......: _GDIPlus_BitmapSetPixel
; Link ..........; @@MsdnLink@@ GdipBitmapGetPixel
; Example .......; Yes
; ===============================================================================================================================
Func _GDIPlus_BitmapGetPixel($hBitmap, $iX, $iY)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipBitmapGetPixel", "hwnd", $hBitmap, "int", $iX, "int", $iY, "uint*", 0)

    If @error Then Return SetError(@error, @extended, 0)
    $GDIP_STATUS = $aResult[0]
    Return $aResult[4]
EndFunc   ;==>_GDIPlus_BitmapGetPixel

Taken from the library

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

  • 2 weeks later...

Sorry for the very late response, yes thank you for your help! I got but one question left, is it possible to have pause and start on the same hotkey?

Example:

F1 to start the script, press F1 again and it's paused, F1 yet again and you start the script again etc etc.

Best regards,

Tender

Link to comment
Share on other sites

  • 2 weeks later...

Check this

HotKeySet("b", "HotKEY_Func_")

;use this when only an interval of two is required.
Func HotKEY_Func_()

    ;we would use boolean values in this case.

    ;this Static variable is a Global Variable which only has scope inside this funciton
    Static $fCount = True

    $fCount = Not $fCount   ;change True to False and vice-versa.

    ;if true
    If $fCount Then ConsoleWrite(">Execute Function no. 1 now." & @CRLF)

    ;if false
    If Not $fCount Then ConsoleWrite(">Execute Function no. 2 now." & @CRLF)

EndFunc



HotKeySet("a", "HotKEY_Func")

;use this when more than two intervals are required.
Func HotKEY_Func()

    ;we would use integer values in this case.

    ;this Static variable is a Global Variable which only has scope inside this funciton
    Static $iCount = 0

    ;base your functions under a specific interval integer.

    ;assuming we have four functions
    ;each would be executed according to its number.
    Local $iFunction_Index = Mod($iCount, 4) + 1    ;added "1" so that there is no "0"th func.
    ConsoleWrite("+Execute Function no. " & $iFunction_Index & " now." & @CRLF)


    ;increment the count by one.
    $iCount += 1


EndFunc   ;==>HotKEY_Func


Do
    Sleep(10)
Until 0

Regards :)

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

  • 2 weeks later...

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...