james3mg Posted February 24, 2010 Share Posted February 24, 2010 (edited) Hello all...I have a feeling that others have likely already run across this problem, but I've searched the forums for a few days, a few ways, and can't find anything referencing it. Please feel free to point me to an existing topic if you know of one. What I'm trying to do is to use the GDIplus functions to create translucent (or semi-transparent) shapes in my GUI. I thought GDIplus was the best candidate because of the alpha channel portion of all the color definitions for pens and brushes. However, what I find is that reducing the alpha on a pen or brush does appear to blend the color with the GUI background color as expected, but it doesn't blend with anything else...that is, it doesn't allow objects/colors/lines/etc to "show through" what should be translucent. Here is a script to show what I mean:expandcollapse popup#include <ButtonConstants.au3> #include <GdiPlus.au3> _GDIPlus_Startup() Global $hGUI=GUICreate("Alpha test",400,400) $ContextMenu=GUICtrlCreateContextMenu() $SavePicture=GUICtrlCreateMenuItem("Save picture",$ContextMenu) $button=GUICtrlCreateButton("A test button- I thought this should ""show through"" anything with less than full alpha",50,100,300,40,$BS_MULTILINE) $hGraphic=_GDIPlus_GraphicsCreateFromHWND($hGUI) $hBMP=_GDIPlus_BitmapCreateFromGraphics(400,400,$hGraphic) $hImage=_GDIPlus_ImageGetGraphicsContext($hBMP) For $i=1 To 15 $hPen=_GDIPlus_PenCreate(BitOR(0xFF000000-((0xFF000000/15)*$i),0xFF0000),1) _GDIPlus_GraphicsDrawLine($hImage,0,200-$i,400,200-$i,$hPen) _GDIPlus_GraphicsDrawLine($hImage,0,199+$i,400,199+$i,$hPen) _GDIPlus_PenDispose($hPen) Next For $i=1 To 15 $hPen=_GDIPlus_PenCreate(BitOR(0xFF000000-((0xFF000000/15)*$i),0x0000FF),1) _GDIPlus_GraphicsDrawLine($hImage,200-$i,0,200-$i,400,$hPen) _GDIPlus_GraphicsDrawLine($hImage,199+$i,0,199+$i,400,$hPen) _GDIPlus_PenDispose($hPen) Next _GDIPlus_GraphicsDispose($hImage) GUISetState() Do _GDIPlus_GraphicsDrawImageRect($hGraphic,$hBMP,0,0,400,400) $msg=GUIGetMsg() If $msg<0 Then ContinueLoop If $msg=$SavePicture Then $SaveFile=FileSaveDialog("Save image as...","","png image (*.png)|jpg image (*.jpg)|gif image (*.gif)",18,"Output.png") If NOT @error Then _GDIPlus_ImageSaveToFile($hBMP, $SaveFile) EndIf sleep(15) Until $msg = -3As you can see, I reduce the alpha channel of the lines as they move away from center, and they appear as intended where they're just over the GUI. However, where they cross each other or another control, they paint right over each other instead of blending and allowing them to be seen "through". Do I not understand how the alpha channel is supposed to work, or am I using it the wrong way, or is this a known problem? Thanks for your input! Edited February 24, 2010 by james3mg "There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110 Link to comment Share on other sites More sharing options...
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
Already have an account? Sign in here.Sign In Now