Sign in to follow this  
Followers 0
MikeP

Transparency, PNG disappearing

13 posts in this topic

#1 ·  Posted (edited)

Hi. I'm looking to use a file with transparency (GIF...BMP..PNG.. whatever works) on my GUI and after a couple of hours I'm at the same point... the transparent regions displays white, so I've searched and searched and found that prospeed UDF could do the work, unfortunately almost all files on the website are down.. and I can't download and test prospeed.

Anyone can help ? for my transparency problem or prospeed.

Thanks

Edited by MikeP

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Check out the AlphaBlend example included with AutoIt.

C:\Program Files\AutoIt3\Examples\GUI\Advanced\AlphaBlend.au3

edit: only works with PNG i believe.

Edited by spudw2k

Share this post


Link to post
Share on other sites

Thanks man ! this is a bit too much than what I wanted.. but in fact you led me in the right direction.. No idea why I was stucked using GUICtrlCreatePic and didn't even think of checking _GDIPlus stuff.. I've been on the pc for too long and I'm starting losing neurons :)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Ok .. I'm facing another problem. I used _GDIPlus_GraphicsDrawImageRectRect to display a PNG on my GUI (I just did the same as what's done in ShowPNG.au3 in the Examples) .. all good but the problem is when I'm putting a window over my GUI and putting it away my PNG disappears :)

So I've put the function inside the main loop, which works since every loop the image is redrawn.. (no idea of the resource consumption..) but there comes another issue.. the shadows which were soft at start are added and added up to the point they're full black..

Sooo the answer would be .. to only redraw the image when it has been hidden by another window.. the fact is I have no clue how to detect if something's hiding the GUI, or part of the GUI...

here is a sample script to demonstrate my problem :

#include <GUIConstants.au3>
#include <GDIPlus.au3>
#include <GuiConstantsEx.au3>
#Include <WinAPI.au3>

$redraw = False
$gui = GUICreate("",200,200)
GUISetBkColor(0xFFFFFF)
GUISetState()
GUICtrlCreateLabel("Hover another window over this and move it away ...the boat disappear"&@CRLF&@CRLF&@CRLF&"To correct this, we can redraw the picture non stop.. Press Enable to do it and check what's happening to the shadow", 90,2,105,180)
$btn = GUICtrlCreateButton("Enable", 120, 180, 60, 20)
_GDIPlus_StartUp()
$hImage   = _GDIPlus_ImageLoadFromFile("sailboat.png")
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($gui)
_GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hImage, 0, 0, 84, 128, 5, 20, 84, 128)

While 1
    $msg = GUIGetMsg()
    Switch $msg
    Case $btn 
        $redraw = True
    Case $GUI_EVENT_CLOSE
        mainwindowClose()
    EndSwitch
    If $redraw Then
        $hImage   = _GDIPlus_ImageLoadFromFile("sailboat.png")
        $hGraphic = _GDIPlus_GraphicsCreateFromHWND($gui)
        _GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hImage, 0, 0, 84, 128, 5, 20, 84, 128)
    EndIf
    Sleep(100)
WEnd

Func mainwindowClose ()
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_ShutDown()
    Exit
EndFunc

and the files in attachment to test it.

Thanks for your help.

pngproblem.au3

Edited by MikeP

Share this post


Link to post
Share on other sites

Ok .. I'm facing another problem. I used _GDIPlus_GraphicsDrawImageRectRect to display a PNG on my GUI (I just did the same as what's done in ShowPNG.au3 in the Examples) .. all good but the problem is when I'm putting a window over my GUI and putting it away my PNG disappears :)

So I've put the function inside the main loop, which works since every loop the image is redrawn.. (no idea of the resource consumption..) but there comes another issue.. the shadows which were soft at start are added and added up to the point they're full black..

Sooo the answer would be .. to only redraw the image when it has been hidden by another window.. the fact is I have no clue how to detect if something's hiding the GUI, or part of the GUI...

You have two choices:

1) catch WM_PAINT by GUIRegisterMsg()

2) use STM_SETIMAGE message

ad 1) search forum for WM_PAINT

ad 2) Look here: http://www.autoitscript.com/forum/index.php?showtopic=51103

Func _SetBitmapToCtrl($CtrlId, $hBitmap)
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    Local Const $SS_BITMAP = 0xE
    Local Const $GWL_STYLE = -16

    Local $hWnd = GUICtrlGetHandle($CtrlId)
    If $hWnd = 0 Then Return SetError(1, 0, 0)
        ; set SS_BITMAP style to control
    Local $oldStyle = DllCall("user32.dll", "long", "GetWindowLong", "hwnd", $hWnd, "int", $GWL_STYLE)
    If @error Then Return SetError(2, 0, 0)
    DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hWnd, "int", $GWL_STYLE, "long", BitOR($oldStyle[0], $SS_BITMAP))
    If @error Then Return SetError(3, 0, 0)
        Local $oldBmp = DllCall("user32.dll", "hwnd", "SendMessage", "hwnd", $hWnd, "int", $STM_SETIMAGE, "int", $IMAGE_BITMAP, "int", $hBitmap)
    If @error Then Return SetError(4, 0, 0)
    If $oldBmp[0] <> 0 Then _WinAPI_DeleteObject($oldBmp[0])
    Return 1
EndFunc

Share this post


Link to post
Share on other sites

Thanks.. I guess I really have to install the other package now because you're using AutoItWrapper and I don't have this (no clue what is too) ..and downloading ResHacker and putting it in my script dir or Autoit dir didn't work either... I guess that's my issue..

Share this post


Link to post
Share on other sites

Thanks.. I guess I really have to install the other package now because you're using AutoItWrapper and I don't have this (no clue what is too) ..and downloading ResHacker and putting it in my script dir or Autoit dir didn't work either... I guess that's my issue..

You don't need whole reources UDF. I just gave you link as example of use _SetBitmapToCtrl()

Look here: http://www.autoitscript.com/forum/index.ph...st&p=517699

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Oh ok.. anyway I already saw that post about resources and I buffered it in my incredible list of "to do or to check" things so I would eventually have had to install it :( .. because the whole thing seems to be really useful ^^

/off-topic : oh god.. I installed Scite4 .. so AutoIt is getting far from being a simple scripting language :D .. that's just awesome what we can do and all the features in there. I loved when I compiled my script and got that big compile options popup I was like... WOW !

mmm k.. let's not get too much excited but I'll sum it up : AutoIt ROCKS :)

Edited by MikeP

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

I might be dumb but I can't get it to work.. anyone see what's wrong in here :

#include <GUIConstants.au3>
#include <GDIPlus.au3>
#include <GuiConstantsEx.au3>
#include <WinAPI.au3>

$gui = GUICreate("", 200, 200)
GUISetBkColor(0xFFFFFF)
GUISetState()
_GDIPlus_Startup()
$hImage   = _GDIPlus_ImageLoadFromFile("sailboat.png")
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
$picCtrl = GUICtrlCreatePic("sailboat.png",0,0,84,128)
_SetBitmapToCtrl($picCtrl, $hBitmap)

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            mainwindowClose()
    EndSwitch
    Sleep(100)
WEnd

Func mainwindowClose()
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_Shutdown()
    Exit
EndFunc   ;==>mainwindowClose

Func _SetBitmapToCtrl($CtrlId, $hBitmap)
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    Local Const $SS_BITMAP = 0xE
    Local Const $GWL_STYLE = -16

    Local $hWnd = GUICtrlGetHandle($CtrlId)
    If $hWnd = 0 Then Return SetError(1, 0, 0)
    ; set SS_BITMAP style to control
    Local $oldStyle = DllCall("user32.dll", "long", "GetWindowLong", "hwnd", $hWnd, "int", $GWL_STYLE)
    If @error Then Return SetError(2, 0, 0)
    DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hWnd, "int", $GWL_STYLE, "long", BitOR($oldStyle[0], $SS_BITMAP))
    If @error Then Return SetError(3, 0, 0)
    Local $oldBmp = DllCall("user32.dll", "hwnd", "SendMessage", "hwnd", $hWnd, "int", $STM_SETIMAGE, "int", $IMAGE_BITMAP, "int", $hBitmap)
    If @error Then Return SetError(4, 0, 0)
    If $oldBmp[0] <> 0 Then _WinAPI_DeleteObject($oldBmp[0])
    Return 1
EndFunc   ;==>_SetBitmapToCtrl

I've been trying to put that damn PNG for the whole day now and this is driving me crazy

Edited by MikeP

Share this post


Link to post
Share on other sites

#11 ·  Posted

Try this changed order:

$gui = GUICreate("", 200, 200)
GUISetBkColor(0xFFFFFF)
_GDIPlus_Startup()
$hImage   = _GDIPlus_ImageLoadFromFile("sailboat.png")
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
$picCtrl = GUICtrlCreatePic("sailboat.png",0,0,84,128)
$hPicCtrl = GUICtrlGetHandle($picCtrl)
_SetBitmapToCtrl($picCtrl, $hBitmap)
GUISetState()

Also try:

$hImage   = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\sailboat.png")

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

nope.. the picture doesn't display :(

edit : YEEEEEEEEEEEEEEEEeeeeeeeeeeeeeeeeeeeeeeeeeeeeees

I found the bug.. you will explain why it happens if you want haha.. but my thing works!

the bug : loading image with _ImageLoadFromFile >> ok

.. putting the same file in the GUICtrlCreatePic control >> NOT ok (no idea why)

I just putted this : $picCtrl = GUICtrlCreatePic("", 0, 0, 84, 128) and it works now ! with your nice function I can hide the GUI behind a window and when i'm getting the GUI back on top the PNG still displays !!!

Thanks Zedna ! (4000+ posts ! nice :) )

p.s : damn that looks ridiculous .."woohoo I found how to put a picture with transparency on my GUI !! the happiest man on Earth!"

Edited by MikeP

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

GUICtrlCreatePic("sailboat.png",0,0,84,128)

I didn't noticed you provided PNG filename here. I just copied your code.

This is of course wrong because PNG is not supported inative mage type for GUICtrlCreatePic() so picture control hasn't been created (correctly).

In such case you must always use empty filename.

BTW: Thanks to 4000+ posts congratulation :)

Edited by Zedna

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