Sign in to follow this  
Followers 0
jerem488

clear a part of picture

12 posts in this topic

Hello,

I don't know how proceed to clear a part of picture (like on the picture on this topic). I have coordinates of selection to clear.

I have testing with _GDIPlus_GraphicsDrawRect(), but the function returns nothing

Thanks in advance

post-24962-0-20293500-1295719820_thumb.p


Qui ose gagneWho Dares Win[left]CyberExploit[/left]

Share this post


Link to post
Share on other sites



It isn't possible to clear with autoit ??

Or, can we draw a transparent picture ?

Because I must superimpose multiple images.


Qui ose gagneWho Dares Win[left]CyberExploit[/left]

Share this post


Link to post
Share on other sites

Nobody have a solution ?

Share this post


Link to post
Share on other sites

Try this:

#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
Opt('MustDeclareVars', 1)
Opt("GUIOnEventMode", 1)
Local $hWnd, $hGraphics, $hBackbuffer, $hBitmap, $file, $hImage, $hBrush
Local $iW, $iH

$file = @ScriptDir & "\Info.png"

_GDIPlus_Startup()

$hImage = _GDIPlus_ImageLoadFromFile($file)

$iW= _GDIPlus_ImageGetWidth($hImage)
$iH = _GDIPlus_ImageGetHeight($hImage)

$hWnd = GUICreate("GDI+ Test", $iW, $iH)
GUISetState()

$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hWnd)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphics)
$hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
$hBrush = _GDIPlus_BrushCreateSolid(0xFF000000); used to clearing below

_GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, 0, 0, $iW, $iH) ;copy image to backbuffer
_GDIPlus_GraphicsFillRect($hBackbuffer, 0, 0, $iW, 200, $hBrush) ;clear part of the image
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $iW, $iH) ;copy backbuffer to GUI
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

Do
Until Not Sleep(30)

Func _Exit()
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hBackbuffer)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    Exit
EndFunc

Br,

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!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

You don't clear, you draw something over.

What is the difference when you want to clear an area? :)

I thought he was already doing that (the white squares)

I don't know whether this is what jerem488 is searching! His description is unfortunately a little bit too short.

Br,

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!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

ATR,

Interesting first post! Anyway, welcome to the AutoIt forum. :)

Making an area of a GUI transparent - which is what I think the OP wants - is not too hard: :idiot:

#include <GUIConstantsEx.au3>
#include <WinAPI.au3>

$hGUI = GUICreate("Test", 500, 500)
GUISetBkColor(0xFF0000)

_GUICreateInvRect($hGUI, 50, 50, 80, 30)

GUISetState()

While 1
  If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
Wend

Func _GUICreateInvRect($hWnd, $iX, $iY, $iW, $iH)

    $aPos = WinGetPos($hWnd)

    Local $hMask_1 = _WinAPI_CreateRectRgn(0, 0, $aPos[2], $iY)
    Local $hMask_2 = _WinAPI_CreateRectRgn(0, 0, $iX, $aPos[3])
    Local $hMask_3 = _WinAPI_CreateRectRgn($iX + $iW, 0, $aPos[2], $aPos[3])
    Local $hMask_4 = _WinAPI_CreateRectRgn(0, $iY + $iH, $aPos[2], $aPos[3])

    _WinAPI_CombineRgn($hMask_1, $hMask_1, $hMask_2, 2)
    _WinAPI_CombineRgn($hMask_1, $hMask_1, $hMask_3, 2)
    _WinAPI_CombineRgn($hMask_1, $hMask_1, $hMask_4, 2)

    _WinAPI_DeleteObject($hMask_2)
    _WinAPI_DeleteObject($hMask_3)
    _WinAPI_DeleteObject($hMask_4)

    _WinAPI_SetWindowRgn($hWnd, $hMask_1, 1)

EndFunc

But I cannot make it set 2 areas transparent - as his image seemed to show. ;)

M23

Edit: A bit more Googling seems to show that you cannot. The existing region is deleted when you set another. :idiot:

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

What is the difference when you want to clear an area? ;)

But it isn't clearing. You don't GUICtrlDelete graphics like some newbies seem to believe sometimes. You draw stuff over the old stuff.

You stuff the stuff over the stuff in the stuff under the stuff stuff.....

:)

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Try this for transparency:

;coded by UEZ 2011
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>

Global $hGUI, $hImage, $hGraphic, $hImage
Global Const $SC_DRAGMOVE = 0xF012
_GDIPlus_Startup()
; Load PNG image
$hImage = _GDIPlus_ImageLoadFromFile("info.png")
$iWidth = _GDIPlus_ImageGetWidth($hImage)
$iHeight = _GDIPlus_ImageGetHeight($hImage)
ConsoleWrite($iWidth & " / " & $iHeight)
; Create GUI
$hGUI = GUICreate("Show PNG", $iWidth, $iHeight, -1, -1, $WS_POPUP, $WS_EX_LAYERED + $WS_EX_TOPMOST)
GUISetState(@SW_SHOW, $hGUI)
SetTransparentBitmap($hGUI, $hImage)

GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            GUIRegisterMsg($WM_LBUTTONDOWN, "")
            _GDIPlus_ImageDispose($hImage)
            _GDIPlus_GraphicsDispose($hGraphic)
            _GDIPlus_Shutdown()
            GUIDelete($hGUI)
            ExitLoop
    EndSwitch
WEnd

Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
    _SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)
EndFunc   ;==>_WM_LBUTTONDOWN

Func SetTransparentBitmap($hGUI, $hImage, $iOpacity = 0xFF)
    Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend
    $hScrDC = _WinAPI_GetDC(0)
    $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)
    $tSize = DllStructCreate($tagSIZE)
    $pSize = DllStructGetPtr($tSize)
    DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth($hImage))
    DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage))
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", $iOpacity)
    DllStructSetData($tBlend, "Format", 1)
    _WinAPI_UpdateLayeredWindow($hGUI, $hGUI, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
    _WinAPI_ReleaseDC(0, $hScrDC)
    _WinAPI_SelectObject($hMemDC, $hOld)
    _WinAPI_DeleteObject($hBitmap)
    _WinAPI_DeleteDC($hMemDC)
EndFunc   ;==>SetTransparentBitmap

Edit: removed not needed lines.

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!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

Try this for transparency:

;coded by UEZ 2011
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>

Global $hGUI, $hImage, $hGraphic, $hImage
Global Const $SC_DRAGMOVE = 0xF012
_GDIPlus_Startup()
; Load PNG image
$hImage = _GDIPlus_ImageLoadFromFile("info.png")
$iWidth = _GDIPlus_ImageGetWidth($hImage)
$iHeight = _GDIPlus_ImageGetHeight($hImage)
ConsoleWrite($iWidth & " / " & $iHeight)
; Create GUI
$hGUI = GUICreate("Show PNG", $iWidth, $iHeight, -1, -1, $WS_POPUP, $WS_EX_LAYERED + $WS_EX_TOPMOST)
GUISetState(@SW_SHOW, $hGUI)
SetTransparentBitmap($hGUI, $hImage)

GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            GUIRegisterMsg($WM_LBUTTONDOWN, "")
            _GDIPlus_ImageDispose($hImage)
            _GDIPlus_GraphicsDispose($hGraphic)
            _GDIPlus_Shutdown()
            GUIDelete($hGUI)
            ExitLoop
    EndSwitch
WEnd

Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
    _SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)
EndFunc   ;==>_WM_LBUTTONDOWN

Func SetTransparentBitmap($hGUI, $hImage, $iOpacity = 0xFF)
    Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend
    $hScrDC = _WinAPI_GetDC(0)
    $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)
    $tSize = DllStructCreate($tagSIZE)
    $pSize = DllStructGetPtr($tSize)
    DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth($hImage))
    DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage))
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", $iOpacity)
    DllStructSetData($tBlend, "Format", 1)
    _WinAPI_UpdateLayeredWindow($hGUI, $hGUI, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
    _WinAPI_ReleaseDC(0, $hScrDC)
    _WinAPI_SelectObject($hMemDC, $hOld)
    _WinAPI_DeleteObject($hBitmap)
    _WinAPI_DeleteDC($hMemDC)
EndFunc   ;==>SetTransparentBitmap

Edit: removed not needed lines.

Br,

UEZ

Perhaps the code work, but I don't understand !!

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
Sign in to follow this  
Followers 0