Sign in to follow this  
Followers 0
oren

draw a circle over a background image

7 posts in this topic

Hello ,

I'm tring to draw a circle over a background image but its seems that the background imagealways over the circle

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
GUICreate("backgammon",800,600)

GUICtrlCreatePic ( "BackPic.jpg", 1, 1,800,600,"",0x00000080) 

$a = GUICtrlCreateGraphic(220, 10, 100, 100)
GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 50, 50)

    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0, 0xff)
    GUICtrlSetGraphic(-1, $GUI_GR_PIE, 50, 50, 40, 30,360)

GUISetState(@sw_show)


while 1
    WEnd

What can I do?

Share this post


Link to post
Share on other sites



try this from the help file remarks for GUICtrlCreatePic.

If a picture is set as a background picture, as the other controls will overlap, it's important to disable the pic control and create it after the others controls: GuiCtrlSetState(-1,$GUI_DISABLE). This is not enough for Tab or Listview control which behave differently. In this case you need to create the picture with the $WS_CLIPSIBLINGS style, GuiCtrlSetState(-1,$GUI_ONTOP) is necessary for the Tab, TreeView or Listview control.


GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

try this from the help file remarks for GUICtrlCreatePic.

If a picture is set as a background picture, as the other controls will overlap, it's important to disable the pic control and create it after the others controls: GuiCtrlSetState(-1,$GUI_DISABLE). This is not enough for Tab or Listview control which behave differently. In this case you need to create the picture with the $WS_CLIPSIBLINGS style, GuiCtrlSetState(-1,$GUI_ONTOP) is necessary for the Tab, TreeView or Listview control.

\

and create it after the others controls

Thanks, Dont know how I missed, But I need to make some controls after I make the background, The controls are dynamic , In the program run I need to delete some controls and create some, depending on the user inputs, What can I do? Thank you

P.S

It still does not work

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

GUICreate("backgammon",800,600)
$a = GUICtrlCreateGraphic(0, 0, 800, 600)
GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 50, 50)

    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0, 0xff)
    GUICtrlSetGraphic(-1, $GUI_GR_PIE, 50, 50, 40, 30,360)



 GUICtrlCreatePic ( "BackPic.jpg", 1, 1,800,600)
 GuiCtrlSetState(-1,$GUI_DISABLE)
 GUISetState(@sw_show)
while 1
    WEnd

post-35491-12697128442463_thumb.jpg

Edited by oren

Share this post


Link to post
Share on other sites

I'm not sure if your two posts are related. You could draw right on the picture if you used a png instead. You will have to put a image called "test.png" in your script directory, but below demonstrates my thought on this.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#Include <Array.au3>

Opt("GUIOnEventMode",1)

_GDIPlus_Startup()
Global $iconname=@ScriptDir & "\test.png"
global $oldImage = _GDIPlus_ImageLoadFromFile($iconname)
Global $GUI
Global $iW = 300
Global $iH = 300
global $object,$background
    $GUI = GUICreate("test", $iW, $iH, -1, -1, $WS_POPUP,bitor($WS_EX_TOOLWINDOW,$WS_EX_LAYERED))
        GUISetState(@SW_SHOWNOACTIVATE, $GUI)
global $xco=150,$yco=0
$object=_Imagechange()
SetBitmap($GUI, $object, 255)
;guistart()
$donx=+2
$dony=+2
While 1
sleep(10)

WEnd
func onautoitexit()
_WinAPI_DeleteObject($object)    
_GDIPlus_Shutdown()
EndFunc


Func SetBitmap($hGUI, $hImage, $iOpacity)
    ;set up layered window
    Local Const $AC_SRC_ALPHA = 1
    Local Const $ULW_ALPHA = 2
    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", $AC_SRC_ALPHA)
    
    _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
    _WinAPI_ReleaseDC(0, $hScrDC)
    _WinAPI_SelectObject($hMemDC, $hOld)
    _WinAPI_DeleteObject($hBitmap)
    _WinAPI_DeleteDC($hMemDC)
EndFunc ;==>SetBitmap
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Func _Imagechange()
    ;resize the png
    Local $GC, $newBmp, $newGC
   ; Load Image

   ;Create New image
    $GC = _GDIPlus_ImageGetGraphicsContext($oldImage)
    $newBmp = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $GC)
    $newGC = _GDIPlus_ImageGetGraphicsContext($newBmp)
   ;Draw
    _GDIPlus_GraphicsDrawImageRect($newGC, $oldImage, 0, 0, $iW, $iH)
        $hbrush2 = _GDIPlus_BrushCreateSolid(0xFF000000)
        $hbrush = _GDIPlus_BrushCreateSolid(0xFF990000)
        for $i=10 to 310 step 50
            _GDIPlus_GraphicsFillPie($newGC, $i-2,8,39, 39, 0, 360,$hbrush2)
            _GDIPlus_GraphicsFillPie($newGC, $i,10,36, 36, 0, 360,$hbrush)
    Next
   ;Cleanup
   ;_GDIPlus_BitmapDispose($newBmp)
       _GDIPlus_BrushDispose($hbrush)
       _GDIPlus_BrushDispose($hbrush2)
    _GDIPlus_GraphicsDispose($GC)
    _GDIPlus_GraphicsDispose($newGC)

    Return $newBmp
EndFunc  ;==>_ImageResize

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

http://www.autoitscript.com/forum/index.php?showtopic=102082&view=findpost&p=725140 '> #725140

GUICtrlCreateGraphic() is painted always at bottom layer by design.

So I think you should use some GDI API functions for painting of your rectangle and label over picture.

Look into latest beta and its WinAPI UDF.

Edit:- Take a look at this udf you might find it usefull although its called icons it uses other formats like jpg as well http://www.autoitscript.com/forum/index.php?showtopic=92675&hl=icons&st=0

p.s. dont forget to use the forum search tool yourself.

Edited by Yoriz

GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.

Share this post


Link to post
Share on other sites

Different approach can be to use Windows GDI API drawing functions inside WM_PAINT for drawing your graphic primitives.

It's very simple, you can look at my Radar project where I draw red cross over GIF image by this technique:

http://www.autoitscript.com/forum/index.php?showtopic=75659

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