Jump to content

Visual Selection Tool for Crop


Parsix
 Share

Recommended Posts

  • Moderators

Parsix,

I posted a couple of example scripts in this thread which might help:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Just an non-perfect example which you can start with:

;coded by UEZ build 2018-09-22 beta
#include <Array.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WinAPIRes.au3>
#include <WinAPISysWin.au3>
#include <WindowsConstants.au3>

Global $__g_hGUI_MarkArea, $__g_iLabel_TL, $__g_iLabel_TM, $__g_iLabel_TR, $__g_iLabel_LM, $__g_iLabel_RM, $__g_iLabel_BL, $__g_iLabel_BM, _
        $__g_iLabel_BR, $__g_iOldCursor, $__g_iW, $__g_iH, $__g_iColor_ResizeDots = 0xFFFFFF, $__g_iBorder = 4

Global $aRect = _GDIPlus_MarkArea()
_ArrayDisplay($aRect, "Selection Coordinates")

Func _GDIPlus_MarkArea()
    _GDIPlus_Startup()
    $__g_hGUI_MarkArea = GUICreate("", 1, 1, -1, -1, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_LAYERED))
    GUISetBkColor(0xABCDEF, $__g_hGUI_MarkArea)

    $__g_iLabel_TL = GUICtrlCreateLabel("", 0, 0, $__g_iBorder, $__g_iBorder) ;top left
    GUICtrlSetResizing(-1, $GUI_DOCKSIZE)
    GUICtrlSetBkColor(-1, $__g_iColor_ResizeDots)
    $__g_iLabel_TM = GUICtrlCreateLabel("", 0, 0, $__g_iBorder, $__g_iBorder) ;top mid
    GUICtrlSetResizing(-1, $GUI_DOCKSIZE)
    GUICtrlSetBkColor(-1, $__g_iColor_ResizeDots)
    $__g_iLabel_TR = GUICtrlCreateLabel("", 0, 0, $__g_iBorder, $__g_iBorder) ;top right
    GUICtrlSetResizing(-1, $GUI_DOCKSIZE)
    GUICtrlSetBkColor(-1, $__g_iColor_ResizeDots)
    $__g_iLabel_LM = GUICtrlCreateLabel("", 0, 0, $__g_iBorder, $__g_iBorder) ;left mid
    GUICtrlSetResizing(-1, $GUI_DOCKSIZE)
    GUICtrlSetBkColor(-1, $__g_iColor_ResizeDots)
    $__g_iLabel_RM = GUICtrlCreateLabel("", 0, 0, $__g_iBorder, $__g_iBorder) ;right mid
    GUICtrlSetResizing(-1, $GUI_DOCKSIZE)
    GUICtrlSetBkColor(-1, $__g_iColor_ResizeDots)
    $__g_iLabel_BL = GUICtrlCreateLabel("", 0, 0, $__g_iBorder, $__g_iBorder) ;bottom left
    GUICtrlSetResizing(-1, $GUI_DOCKSIZE)
    GUICtrlSetBkColor(-1, $__g_iColor_ResizeDots)
    $__g_iLabel_BM = GUICtrlCreateLabel("", 0, 0, $__g_iBorder, $__g_iBorder) ;bottom mid
    GUICtrlSetResizing(-1, $GUI_DOCKSIZE)
    GUICtrlSetBkColor(-1, $__g_iColor_ResizeDots)
    $__g_iLabel_BR = GUICtrlCreateLabel("", 0, 0, $__g_iBorder, $__g_iBorder) ;bottom right
    GUICtrlSetResizing(-1, $GUI_DOCKSIZE)
    GUICtrlSetBkColor(-1, $__g_iColor_ResizeDots)
    $__g_iOldCursor = MouseGetCursor()
    GUISetCursor(3, 1, $__g_hGUI_MarkArea)
    GUISetState(@SW_SHOW, $__g_hGUI_MarkArea)
    _WinAPI_SetLayeredWindowAttributes($__g_hGUI_MarkArea, 0xABCDEF, 0xF0, 3)

    Local $aMPos, $aPrevMPos[2] = [MouseGetPos(0) + 1, MouseGetPos(1) + 1], $iID, $aCI, $iX, $iY, $bLMPressed = False

    Do
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                GUIRegisterMsg($WM_TIMER, "")
                DllCall("user32.dll", "bool", "KillTimer", "hwnd", $__g_hGUI_MarkArea, "uint_ptr", $iID)
                _GDIPlus_Shutdown()
                Local $aResult = WinGetPos($__g_hGUI_MarkArea)
                GUIDelete($__g_hGUI_MarkArea)
                Return $aResult
        EndSwitch
        $aMPos = MouseGetPos()
        If $aMPos[0] <> $aPrevMPos[0] Or $aMPos[1] <> $aPrevMPos[1] And Not $bLMPressed Then
            WinMove($__g_hGUI_MarkArea, "", $aMPos[0], $aMPos[1])
            $aPrevMPos = $aMPos
        EndIf
        $aCI = GUIGetCursorInfo($__g_hGUI_MarkArea)
        If $bLMPressed = True Then
            Switch $aCI[4]
                Case $__g_iLabel_TL, $__g_iLabel_BR
                    GUISetCursor(12, 1, $__g_hGUI_MarkArea)
                Case $__g_iLabel_TR, $__g_iLabel_BL
                    GUISetCursor(10, 1, $__g_hGUI_MarkArea)
                Case $__g_iLabel_LM, $__g_iLabel_RM
                    GUISetCursor(13, 1, $__g_hGUI_MarkArea)
                Case $__g_iLabel_TM, $__g_iLabel_BM
                    GUISetCursor(11, 1, $__g_hGUI_MarkArea)
                Case Else
                    GUISetCursor($__g_iOldCursor, 1, $__g_hGUI_MarkArea)
            EndSwitch
        EndIf
        If $aCI[2] And Not $bLMPressed Then
            $aGUIStartPos = WinGetPos($__g_hGUI_MarkArea)
            GUIRegisterMsg($WM_TIMER, "PlayAnim")
            $iID = DllCall("User32.dll", "uint_ptr", "SetTimer", "hwnd", $__g_hGUI_MarkArea, "uint_ptr", 1, "uint", 30, "ptr", 0)[0]
            While $aCI[2]
                $aCI = GUIGetCursorInfo($__g_hGUI_MarkArea)
                $aMPos = MouseGetPos()
                $__g_iW = Abs($aMPos[0] - $aGUIStartPos[0]) + 1
                $__g_iH = Abs($aMPos[1] - $aGUIStartPos[1]) + 1
                If $aMPos[0] < $aGUIStartPos[0] Then
                    $iX = $aMPos[0]
                Else
                    $iX = $aGUIStartPos[0]
                EndIf
                If $aMPos[1] < $aGUIStartPos[1] Then
                    $iY = $aMPos[1]
                Else
                    $iY = $aGUIStartPos[1]
                EndIf
                WinMove($__g_hGUI_MarkArea, "", $iX, $iY, $__g_iW, $__g_iH)

                ControlMove($__g_hGUI_MarkArea, "", $__g_iLabel_TM, ($__g_iW - $__g_iBorder) / 2, 0, $__g_iBorder, $__g_iBorder)
                ControlMove($__g_hGUI_MarkArea, "", $__g_iLabel_TR, ($__g_iW - $__g_iBorder), 0, $__g_iBorder, $__g_iBorder)
                ControlMove($__g_hGUI_MarkArea, "", $__g_iLabel_LM, 0, ($__g_iH - $__g_iBorder) / 2, $__g_iBorder, $__g_iBorder)
                ControlMove($__g_hGUI_MarkArea, "", $__g_iLabel_RM, ($__g_iW - $__g_iBorder), ($__g_iH - $__g_iBorder) / 2, $__g_iBorder, $__g_iBorder)
                ControlMove($__g_hGUI_MarkArea, "", $__g_iLabel_BL, 0, ($__g_iH - $__g_iBorder), $__g_iBorder, $__g_iBorder)
                ControlMove($__g_hGUI_MarkArea, "", $__g_iLabel_BM, ($__g_iW - $__g_iBorder) / 2, ($__g_iH - $__g_iBorder), $__g_iBorder, $__g_iBorder)
                ControlMove($__g_hGUI_MarkArea, "", $__g_iLabel_BR, ($__g_iW - $__g_iBorder), ($__g_iH - $__g_iBorder), $__g_iBorder, $__g_iBorder)
                ControlMove($__g_hGUI_MarkArea, "", $__g_iLabel_BR, ($__g_iW - $__g_iBorder), ($__g_iH - $__g_iBorder), $__g_iBorder, $__g_iBorder)
            WEnd
            $bLMPressed = True
            GUISetCursor($__g_iOldCursor, 1, $__g_hGUI_MarkArea)
        EndIf
    Until False
EndFunc   ;==>_GDIPlus_MarkArea

Func PlayAnim()
    Local Static $fOffset = 0
    Local Const $iSize = $__g_iBorder / 2
    Local Const $hDC = _WinAPI_GetDC($__g_hGUI_MarkArea)
    Local Const $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $__g_iW, $__g_iH)
    Local Const $hDC_backbuffer = _WinAPI_CreateCompatibleDC($hDC)
    Local Const $DC_obj = _WinAPI_SelectObject($hDC_backbuffer, $hHBitmap)
    Local Const $hCanvas = _GDIPlus_GraphicsCreateFromHDC($hDC_backbuffer)
    Local Const $hPen = _GDIPlus_PenCreate(0xFF0178D7, $iSize), $hPen2 = _GDIPlus_PenCreate(0xFFFFFFFF, $iSize), _
                $hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
    _GDIPlus_PenSetDashStyle($hPen, $GDIP_DASHSTYLEDASHDOTDOT)
    _GDIPlus_GraphicsClear($hCanvas, 0xFFABCDEF)
    _GDIPlus_GraphicsDrawRect($hCanvas, 1 + $iSize, 1 + $iSize, $__g_iW - 2 * $iSize - 2, $__g_iH - 2 * $iSize - 2, $hPen2)
    DllCall($__g_hGDIPDll, "int", "GdipSetPenDashOffset", "handle", $hPen, "float", $fOffset)
    _GDIPlus_GraphicsDrawRect($hCanvas, 1 + $iSize, 1 + $iSize, $__g_iW - 2 * $iSize - 2, $__g_iH - 2 * $iSize - 2, $hPen)

    _GDIPlus_GraphicsFillRect($hCanvas, 0, 0, $__g_iBorder + 1, $__g_iBorder + 1, $hBrush)
    _GDIPlus_GraphicsDrawRect($hCanvas, 0, 0, $__g_iBorder + 1, $__g_iBorder + 1)
    _GDIPlus_GraphicsFillRect($hCanvas, ($__g_iW - $__g_iBorder) / 2, 0, $__g_iBorder + 1, $__g_iBorder + 1, $hBrush)
    _GDIPlus_GraphicsDrawRect($hCanvas, ($__g_iW - $__g_iBorder) / 2, 0, $__g_iBorder + 1, $__g_iBorder + 1)
    _GDIPlus_GraphicsFillRect($hCanvas, ($__g_iW - $__g_iBorder) - 2, 0, $__g_iBorder + 1, $__g_iBorder + 1, $hBrush)
    _GDIPlus_GraphicsDrawRect($hCanvas, ($__g_iW - $__g_iBorder) - 2, 0, $__g_iBorder + 1, $__g_iBorder + 1)
    _GDIPlus_GraphicsFillRect($hCanvas, 0, ($__g_iH - $__g_iBorder) / 2, $__g_iBorder + 1, $__g_iBorder + 1, $hBrush)
    _GDIPlus_GraphicsDrawRect($hCanvas, 0, ($__g_iH - $__g_iBorder) / 2, $__g_iBorder + 1, $__g_iBorder + 1)
    _GDIPlus_GraphicsFillRect($hCanvas, ($__g_iW - $__g_iBorder) - 2, ($__g_iH - $__g_iBorder) / 2, $__g_iBorder + 1, $__g_iBorder + 1, $hBrush)
    _GDIPlus_GraphicsDrawRect($hCanvas, ($__g_iW - $__g_iBorder) - 2, ($__g_iH - $__g_iBorder) / 2, $__g_iBorder + 1, $__g_iBorder + 1)
    _GDIPlus_GraphicsFillRect($hCanvas, 0, ($__g_iH - $__g_iBorder) - 2, $__g_iBorder + 1, $__g_iBorder + 1, $hBrush)
    _GDIPlus_GraphicsDrawRect($hCanvas, 0, ($__g_iH - $__g_iBorder) - 2, $__g_iBorder + 1, $__g_iBorder + 1)
    _GDIPlus_GraphicsFillRect($hCanvas, ($__g_iW - $__g_iBorder) / 2, ($__g_iH - $__g_iBorder) - 2, $__g_iBorder + 1, $__g_iBorder + 1, $hBrush)
    _GDIPlus_GraphicsDrawRect($hCanvas, ($__g_iW - $__g_iBorder) / 2, ($__g_iH - $__g_iBorder) - 2, $__g_iBorder + 1, $__g_iBorder + 1)
    _GDIPlus_GraphicsFillRect($hCanvas, ($__g_iW - $__g_iBorder) - 2, ($__g_iH - $__g_iBorder) - 2, $__g_iBorder + 1, $__g_iBorder + 1, $hBrush)
    _GDIPlus_GraphicsDrawRect($hCanvas, ($__g_iW - $__g_iBorder) - 2, ($__g_iH - $__g_iBorder) - 2, $__g_iBorder + 1, $__g_iBorder + 1)

    _WinAPI_BitBlt($hDC, 0, 0, $__g_iW, $__g_iH, $hDC_backbuffer, 0, 0, $SRCCOPY)

    $fOffset += 0.5
    _GDIPlus_GraphicsDispose($hCanvas)
    _WinAPI_SelectObject($hDC_backbuffer, $DC_obj)
    _WinAPI_DeleteDC($hDC_backbuffer)
    _WinAPI_DeleteObject($hHBitmap)
    _WinAPI_ReleaseDC($__g_hGUI_MarkArea, $hDC)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_PenDispose($hPen2)
    _GDIPlus_BrushDispose($hBrush)
EndFunc   ;==>PlayAnim

 

Just mark an area on your desktop by holding down the left mouse button. The resize function of the marked area is not added yet.

 

Look here for the full version: 

 

 

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

  • 2 weeks later...
On 10/6/2018 at 4:05 PM, Parsix said:

UEZ

 

thanks, how to accept Selected area?

 only crop a section of pic control is needed

When you have selected an area on your desktop press ESC. The function _GDIPlus_MarkArea() will return an array with x, y, w, h values.

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

1 hour ago, Parsix said:

How to Limit it to _GDIPlus_GraphicsDrawImageRect ?

It do not know what you want to ask with that question! 

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

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...