Jump to content

Drawing Rectangle Box


Xtian
 Share

Recommended Posts

Hi,

can anyone help me how to code the rectangle box?

I'll use it as a cropping tool, and no GUI please.

thnx

and also how can I automatically edit pictures in paint?

Coz after I captured the image I need to edit it on paint.

I used this code and I know that there is a better one ;)

$filename = "somefile.jpg"

Run("mspaint.exe")

send("!f")

send("o")

send($filename)

send("{enter}")

------------

1. draw rectangle to select part of the image to capture (help :[ )

2. Capture image (Done)

3. Edit something in Mspaint (done)

I need this coz I need to take a lot of screenshots.

Thank you.

Sorry for being noob but... thanks to you im learned something new.
Link to comment
Share on other sites

You can find lots of examples if you search. Here's one.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

hmm, the samples are really useful but, can't i make a cropping tool without Gui?

Is there a simple way to do it?

im still a noob here -.-

thnx.

Sorry for being noob but... thanks to you im learned something new.
Link to comment
Share on other sites

I'm currently working on this and it is not finished yet!

Might be helpful for you:

;coded by UEZ build 2010-11-01
#AutoIt3Wrapper_Res_Description=Takes screenshot from marked area on desktop
#AutoIt3Wrapper_Res_ProductVersion=0.5.0.0
#AutoIt3Wrapper_Res_LegalCopyright=UEZ 2010
#AutoIt3Wrapper_Res_Language=1033
://////=__=
://////=__=--
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/sf /sv /om /cs=0 /cn=0
#AutoIt3Wrapper_Run_After=upx.exe --ultra-brute "%out%"
#AutoIt3Wrapper_Run_After=del /f /q "ScreenGrabber_Obfuscated.au3"
#Include <Clipboard.au3>
#include <GDIPlus.au3>
#include <Misc.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
Opt("MustDeclareVars", 1)
TraySetState (2)

Mark_Area("Grabbed.jpg", True)
Exit

Func Mark_Area($filename = "", $execute = False)
    If $filename <> "" And Not StringRegExp($filename, "\.(jpg|bmp|gif|png|tif)$") Then _
        _WinAPI_ShowError($filename & @CRLF & @CRLF & "Unknown file extension (image type)!" & @CRLF & _
                                                     "Valid extensions are: jpg, bmp, gif, png, tif!")
    Local $user32_dll = DllOpen("user32.dll")
    Local $w, $h, $mpos = MouseGetPos()

    Local $hGUI_Cross = GUICreate("", 30, 30, $mpos[0], $mpos[1], $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
    GUISetState(@SW_SHOW, $hGUI_Cross)
    WinSetTrans($hGUI_Cross, "", 1)

    HotKeySet("{ESC}", "_Exit")

    While Not _IsPressed("01", $user32_dll)
        GUISetCursor(3, 1, $hGUI_Cross)
        $mpos = MouseGetPos()
        WinMove($hGUI_Cross, "", $mpos[0] - 15, $mpos[1] - 15)
        ToolTip("Please mark area on your desktop!")
    Sleep(30)
    WEnd
    ToolTip("")
    HotKeySet("{ESC}")

    $mpos = MouseGetPos()
    Local $m_startx = $mpos[0]
    Local $m_starty = $mpos[1]

    Local $hGUI = GUICreate("", 0, 0, $m_startx, $m_starty, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
    GUISetBkColor(0x000040)
    Local $size = 1
    Local $label = GUICtrlCreateLabel("TEST", $size, $size, 0, 0) ;, Default, $WS_EX_COMPOSITED) ;$WS_EX_COMPOSITED is not working with AERO properly
    GUICtrlSetBkColor($label, 0xFFFFB0)
    GUISetState(@SW_SHOW, $hGUI)
    WinSetTrans($hGUI, "", 0x40)
    WinActivate($hGUI)

    #cs
     -------
    | 1 | 3 |
     ---x---
    | 2 | 4 |
     -------
    x = start position of mouse
    #ce
    Do
        GUISetCursor(3, 1, $hGUI_Cross)
        $mpos = MouseGetPos()
        If $mpos[0] < $m_startx And $mpos[1] < $m_starty Then ;1
            $w = $m_startx - $mpos[0]
            $h = $m_starty - $mpos[1]
            WinMove($hGUI, "", $mpos[0], $mpos[1], $w, $h, 1)
            ToolTip($w & "x" & $h, $mpos[0] - 30, $mpos[1] - 30)
        ElseIf $mpos[0] < $m_startx And $mpos[1] > $m_starty Then ;2
            $w = $m_startx - $mpos[0]
            $h = $mpos[1] - $m_starty
            WinMove($hGUI, "", $mpos[0], $m_starty, $m_startx - $mpos[0], $mpos[1] - $m_starty, 1)
            ToolTip($w & "x" & $h)
        ElseIf $mpos[0] > $m_startx And $mpos[1] < $m_starty Then ;3
            $w = $mpos[0] - $m_startx
            $h = $m_starty - $mpos[1]
            WinMove($hGUI, "", $m_startx, $mpos[1], $mpos[0] - $m_startx, $m_starty - $mpos[1], 1)
            ToolTip($w & "x" & $h)
        Else ;4
            $w = $mpos[0] - $m_startx
            $h = $mpos[1] - $m_starty
            WinMove($hGUI, "", $m_startx, $m_starty, $mpos[0] - $m_startx, $mpos[1] - $m_starty, 1)
            ToolTip($w & "x" & $h)
        EndIf
        WinMove($hGUI_Cross, "", $mpos[0] - 15, $mpos[1] - 15)
        GUICtrlSetPos($label, $size, $size, $w - 2 * $size, $h - 2 * $size)
        Sleep(20)
    Until Not _IsPressed("01", $user32_dll)

    DllClose($user32_dll)
    GUIDelete($hGUI_Cross)
    Local $Win_Coord = WinGetPos($hGUI) ;x,y,width,height
    GUIDelete($hGUI)

    Grab_Region($Win_Coord[0], $Win_Coord[1], $Win_Coord[2], $Win_Coord[3], $filename)
    If $filename <> "" And $execute Then ShellExecute($filename)
EndFunc

Func Grab_Region($x, $y, $w, $h, $filename, $jpg_quality = 80)
    Local $err, $err_txt
    Local $hDC = _WinAPI_GetDC(0)
    Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
    Local $memBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $w, $h)
    Local $hObj = _WinAPI_SelectObject($hMemDC, $memBitmap)
    _WinAPI_BitBlt($hMemDC, 0, 0, $w, $h, $hDC, $x, $y, $SRCCOPY)

    _GDIPlus_Startup()
    Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($memBitmap)
    If @error Then Return SetError(1, @extended, _WinAPI_ShowError("Unable to create HBITMAP!"))
    If $filename <> "" Then
        If StringRight($filename, 3) = "jpg" Then
            Local $sCLSID = _GDIPlus_EncodersGetCLSID ("JPG")
            Local $tParams = _GDIPlus_ParamInit (1)
            Local $tData = DllStructCreate("int Quality")
            DllStructSetData($tData, "Quality", $jpg_quality) ;quality 0-100 (poor-best)
            Local $pData = DllStructGetPtr($tData)
            _GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData)
            Local $pParams = DllStructGetPtr($tParams)
            _GDIPlus_ImageSaveToFileEx($hBitmap, $filename, $sCLSID, $pParams)
            $tData = 0
        Else
            _GDIPlus_ImageSaveToFile($hBitmap, $filename)
        EndIf
    Else
        If Not _ClipBoard_Open(0) Then
            $err = @error
            $err_txt = "_ClipBoard_Open failed"
        EndIf
        If Not _ClipBoard_Empty() Then
            $err = @error
            $err_txt = "_ClipBoard_SetDataEx failed"
        EndIf
        If Not _ClipBoard_SetDataEx($memBitmap, $CF_BITMAP) Then
            $err = @error
            $err_txt = "_ClipBoard_Empty failed"
        EndIf
        _ClipBoard_Close()
        If Not $err Then MsgBox(0, "Information", "Image grabbed to clipboard!", 10)
    EndIf
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_Shutdown()

    _WinAPI_DeleteDC($hMemDC)
    _WinAPI_DeleteObject($memBitmap)
    _WinAPI_ReleaseDC(0, $hDC)
    _WinAPI_DeleteDC($hDC)
    If $err Then Return SetError(1, @extended, _WinAPI_ShowError($err_txt))
    Return SetError(0)
EndFunc

Func _Exit()
    Exit
EndFunc

Edit: made some modifications.

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

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