Jump to content

✂️ Quick crop tool


Gianni
 Share

Recommended Posts

Thank you @UEZ for the instructions (and especially for the Italian translation of the steps ... :lol:)
... Ugly beast this DPI; for example by dragging a window between two monitors with different DPI one 100% and one 150%, at some point, when the window is half on one monitor and half on the other, it changes its appearance and the whole window takes on the DPI of the second monitor, thus even the half that is still in the first monitor has the DPI of the second, obtaining a window with a DPI of 150% in a monitor where the DPI is still 100% (strange effect of only that window enlarged compared to others on the same monitor). Another strange effect is that if you take a screenshot on the monitor (ie 125%) and then paste it for example in mspaint always on the same monitor, the pasted image is further enlarged compared to the DPI of the monitor itself (I think this magnification it's not normal...).  :blink: I'm doing some more tests to see if I can figure it out something more ....

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

I used this udf to crop parts of the screen to OCR "on the fly" using <this other udf> by @Danyfirex

1) once running, use ctrl-1 to bring up the crop tool
2) move and resize the tool to choose the area to select
3) Right click inside the selected area to OCR the content. (a MsgBox shows the result)
use the Tray icon to close the program

download both udfs and save them in the same folder together with this script

; download both udfs and save them in the same folder together with this script

#include <.\CropTool.au3>
; https://www.autoitscript.com/forum/topic/203545-%E2%9C%82%EF%B8%8F-quick-crop-tool

#include <.\UWPOCR.au3>
; https://www.autoitscript.com/forum/topic/207324-uwpocr-windows-platform-optical-character-recognition-api-implementation/

#include <ScreenCapture.au3>
Opt("TrayMenuMode", 3) ; The default tray menu items will not be shown and items are not checked when selected. These are options 1 and 2 for TrayMenuMode.
Global $user32 = DllOpen("user32.dll")
_GDIPlus_Startup()

Local $idCrop = TrayCreateItem("Crop")
TrayCreateItem("")     ; Create a separator line.
Local $idExit = TrayCreateItem("Exit")

    TraySetToolTip("Hit ctrl-1 to show crop."&@CRLF&"(move & resize the area)"&@CRLF&"right click in area to OCR"&@CRLF&"hit ESC to cancel")
While 1
    ; hit Control+1 to call the _Crop Function
    If _IsPressed("11", $user32) And _IsPressed("31", $user32) Then ; "11" CTRL key + "31" 1 key
        TrayItemSetState($idCrop, 128)      ; Crop - Menuitem will be greyed out
        TrayItemSetState($idExit, 128)      ; Exit - Menuitem will be greyed out
        _CropAndOCR()
        TrayItemSetState($idCrop, 64)     ; Crop - Menuitem will be enabled
        TrayItemSetState($idExit, 64)     ; Exit - Menuitem will be enabled
    EndIf

    Switch TrayGetMsg()

        Case $idCrop
            TrayItemSetState($idCrop, 128)  ; Crop - Menuitem will be greyed out
            TrayItemSetState($idExit, 128)  ; Exit - Menuitem will be greyed out
            _CropAndOCR()
            TrayItemSetState($idCrop, 64) ; Crop - Menuitem will be enabled
            TrayItemSetState($idExit, 64) ; Exit - Menuitem will be enabled
        Case $idExit     ; Exit the loop.
            ExitLoop
    EndSwitch
WEnd
DllClose($user32)
_GDIPlus_Shutdown()
TrayTip("OCR by crop", "End of the 'TSR' OCR by crop", 3, 1) ; (1) = Info icon
Sleep(3000)
Exit

Func _CropAndOCR()
    $aRect = _Crop() ; mark the area

    If Not @extended Then ; if the ESC key was pressed within the _Crop function the @extended is set to 1
        Local $hTimer = TimerInit()
        Local $hBmp = _ScreenCapture_Capture('', $aRect[0], $aRect[1], $aRect[0] + $aRect[2] - 1, $aRect[1] + $aRect[3] - 1, False)
        Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBmp)

        Local $sOCRTextResult = _UWPOCR_GetText($hBitmap, Default, True)

        _WinAPI_DeleteObject($hBmp)
        _GDIPlus_BitmapDispose($hBitmap)

        MsgBox(0, "Time Elapsed: " & TimerDiff($hTimer), $sOCRTextResult)

        Return $sOCRTextResult

    EndIf
EndFunc   ;==>_CropAndOCR

 

Edited by Gianni

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
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
 Share

×
×
  • Create New...