Jump to content

Transparent picture


Go to solution Solved by Shark007,

Recommended Posts

Hey Guys,
It's my first topic and my english is pretty bad.
Usually I just read and never had a reason to create an Account, but this time I can't solve the problem by simply googling it.
Excuse my bad english.

Is there a way to put a png picture [always on top!] so that I'm able to work below it (drawning) with my mouse/drawingprogram?
I've tried to come up with a solution myself but frankly: I have no Idea how to do it.
And it's also important that I can determine the coordinates where the picture is placed and that it keeps being transparant, and preferably (but not neccesarly)
borderless.

It would be of great help.
Thanks in advance and sorry for giving you a headache reading through this mess.
 

Xavier

Link to comment
Share on other sites

this is ready to use

#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
; #include <WinAPISysWin.au3>
#include <WinAPI.au3>

Global $sFileImage = @TempDir & "\Leopard.png"
If Not FileExists($sFileImage) Then InetGet("http://www.pngall.com/wp-content/uploads/2/Sitting-Leopard-Transparent.png", $sFileImage)
$h = _SetImage(100, 100, $sFileImage)
MsgBox(0, '', "You can drag the image around" & @CRLF & "hit OK to end")
; FileDelete($sFileImage)

Func _SetImage($Left, $Top, $Picture, $iOpacity = 255)
    _GDIPlus_Startup()
    Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend
    Local $hImage = _GDIPlus_ImageLoadFromFile($Picture)
    Local $iWidth = _GDIPlus_ImageGetWidth($hImage)
    Local $iHeight = _GDIPlus_ImageGetHeight($hImage)
    Local $hGUI = GUICreate('', $iWidth, $iHeight, $Left, $Top, $WS_POPUP, $WS_EX_LAYERED + $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
    Local $hLabel = GUICtrlCreateLabel('', 0, 0, $iWidth, $iHeight, -1, $GUI_WS_EX_PARENTDRAG)
    GUISetState(@SW_SHOW, $hGUI)
    $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", $iWidth)
    DllStructSetData($tSize, "Y", $iHeight)
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", $iOpacity)
    DllStructSetData($tBlend, "Format", 1)
    _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)
    _GDIPlus_Shutdown()
    Return $hGUI
EndFunc   ;==>_SetImage

 

 

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

Just in case anyone was searching for a similiar problem, here is how I got it running.


#include <GDIPlus.au3>

 

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
; #include <WinAPISysWin.au3>
#include <WinAPI.au3>

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

Global $sFileImage = "Picture" ;Picture is in the same folder as the au3
$h = _SetImage(100, 100, $sFileImage)

Func _SetImage($Left, $Top, $Picture, $iOpacity = 255)
    _GDIPlus_Startup()
    Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend
    Local $hImage = _GDIPlus_ImageLoadFromFile($Picture)
    Local $iWidth = _GDIPlus_ImageGetWidth($hImage)
    Local $iHeight = _GDIPlus_ImageGetHeight($hImage)
    Local $hGUI = GUICreate('', $iWidth, $iHeight, $Left, $Top, $WS_POPUP, $WS_EX_LAYERED + $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
    Local $hLabel = GUICtrlCreateLabel('', 0, 0, $iWidth, $iHeight, -1, $GUI_WS_EX_PARENTDRAG)
    GUISetState(@SW_SHOW, $hGUI)
    $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", $iWidth)
    DllStructSetData($tSize, "Y", $iHeight)
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", $iOpacity)
    DllStructSetData($tBlend, "Format", 1)
    _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)
    _GDIPlus_Shutdown()
    Return $hGUI
EndFunc   ;==>_SetImage

ToolTip("You can drag the image around" & @CRLF & "Press [ESC] to Exit", 1500, 20)
While 1 ;Loop (otherwise the Programm will be exited automatically, because nothing to do)

WEnd

Func _Exit()
    _GDIPlus_Shutdown()
   Exit
EndFunc
 

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