Page 1 of 1
transparent png on window.
Posted: Sat Sep 29, 2007 8:39 pm
by hss
hi company,
please, have a look at this code..
Code: Select all
UsePNGImageDecoder()
OpenWindow(0,0,0,300,300,"",#PB_Window_ScreenCentered|#PB_Window_BorderLess)
SetWindowLong_(WindowID(0),#GWL_EXSTYLE,GetWindowLong_(WindowID(0),#GWL_EXSTYLE)|#WS_EX_LAYERED)
SetLayeredWindowAttributes_(WindowID(0),RGB(0,255,255),0,#LWA_COLORKEY)
SetWindowColor(0,RGB(0,255,255)):StickyWindow(0,1)
CreateGadgetList(WindowID(0))
; if this, then *glow is* black --->
;ImageGadget(1,0,0,0,0,ImageID(LoadImage(#PB_Any,"c:\ss.png")))
; if this, then *glow* is cyan --->
;StartDrawing(WindowOutput(0))
;DrawAlphaImage(ImageID(LoadImage(#PB_Any,"c:\ss.png")),0,0)
;StopDrawing()
Repeat:E=WaitWindowEvent():Delay(5):Until(E=#PB_Event_CloseWindow):End
that's how it should look like when runnin' the code:
..something wrong with the API?
love,
hss
edit: here's the PNG -
http://img210.imageshack.us/img210/3071/ssqt6.png
Posted: Sat Sep 29, 2007 8:43 pm
by netmaestro
Hard to say exactly without the image to play with but you probably are going to want to or in the alpha flag as well: #LWA_COLORKEY | #LWA_ALPHA to get the proper dropshadow.
Posted: Sat Sep 29, 2007 9:04 pm
by netmaestro
Ok, I see what you're looking for now. You're using the wrong api for that, what you want is UpdateLayeredWindow. But there's a known problem with PureBasic's PNG decoder and that api unfortunately. Here is your image in TIFF format:
http://www.artbysheryl.com/netmaestro/ssqt6.tif
which will work with the api, and here is some code:
Code: Select all
UseTIFFImageDecoder()
img = LoadImage(#PB_Any, "ssqt6.tif")
OpenWindow(0,0,0,300,300,"",#PB_Window_ScreenCentered|#PB_Window_BorderLess)
SetWindowLong_(WindowID(0),#GWL_EXSTYLE,GetWindowLong_(WindowID(0),#GWL_EXSTYLE)|#WS_EX_LAYERED)
CreateGadgetList(WindowID(0))
hDC = StartDrawing(ImageOutput(img))
sz.SIZE
sz\cx = ImageWidth(img)
sz\cy = ImageHeight(img)
ContextOffset.POINT
BlendMode.BLENDFUNCTION
BlendMode\SourceConstantAlpha = 255
BlendMode\AlphaFormat = 1
UpdateLayeredWindow_(WindowID(0), 0, 0, @sz, hDC, @ContextOffset, 0, @BlendMode, 2)
StopDrawing()
ImageGadget(0,0,0,0,0,ImageID(img))
Repeat:E=WaitWindowEvent():Delay(5):Until(E=#PB_Event_CloseWindow):End
If you don't want to use TIFF you can load the PNG using gdiplus and there won't be a problem with UpdateLayeredWindow.
Posted: Sat Sep 29, 2007 9:14 pm
by hss
much thanks to canada :-)
but 270+ kb is too...huh!
so, i prefer to do to without the glow-effect.
maybe the PB.PNG.BUG gets fixed sometime..
-H
edit: ok, let's check gdiplus..
Posted: Sat Sep 29, 2007 9:28 pm
by netmaestro
Fair enough, here is a snippet that will let you use the PNG version without problem:
Code: Select all
Procedure StringToBStr (string$) ; By Zapman Inspired by Fr34k
Protected Unicode$ = Space(Len(String$)* 2 + 2)
Protected bstr_string.l
PokeS(@Unicode$, String$, -1, #PB_Unicode)
bstr_string = SysAllocString_(@Unicode$)
ProcedureReturn bstr_string
EndProcedure
ProcedureDLL LoadDecodedImage(Filename$)
CompilerIf Defined(GdiplusStartupInput, #PB_Structure) = 0
Structure GdiplusStartupInput
GdiPlusVersion.l
*DebugEventCallback.Debug_Event
SuppressBackgroundThread.l
SuppressExternalCodecs.l
EndStructure
CompilerEndIf
OpenLibrary(0, "gdiplus.dll")
input.GdiplusStartupInput
input\GdiPlusVersion = 1
CallFunction(0, "GdiplusStartup", @*token, @input, #Null)
CallFunction(0, "GdipCreateBitmapFromFile", StringToBStr(Filename$), @*image)
CallFunction(0, "GdipGetImageWidth", *image, @Width.l)
CallFunction(0, "GdipGetImageHeight", *image, @Height.l)
CallFunction(0, "GdipCreateHBITMAPFromBitmap", *image, @imageid.l, -1)
CallFunction(0, "GdipDisposeImage", *image)
CallFunction(0, "GdiplusShutdown", *token)
CloseLibrary(0)
return_imagenumber = CreateImage(#PB_Any, width, height, 32)
StartDrawing(ImageOutput(return_imagenumber))
DrawAlphaImage(imageid,0,0)
StopDrawing()
ProcedureReturn return_imagenumber
EndProcedure
img = LoadDecodedImage("ssqt6.png")
OpenWindow(0,0,0,300,300,"",#PB_Window_ScreenCentered|#PB_Window_BorderLess|#PB_Window_Invisible)
SetWindowLong_(WindowID(0),#GWL_EXSTYLE,GetWindowLong_(WindowID(0),#GWL_EXSTYLE)|#WS_EX_LAYERED)
CreateGadgetList(WindowID(0))
hDC = StartDrawing(ImageOutput(img))
sz.SIZE
sz\cx = ImageWidth(img)
sz\cy = ImageHeight(img)
ContextOffset.POINT
BlendMode.BLENDFUNCTION
BlendMode\SourceConstantAlpha = 255
BlendMode\AlphaFormat = 1
UpdateLayeredWindow_(WindowID(0), 0, 0, @sz, hDC, @ContextOffset, 0, @BlendMode, 2)
StopDrawing()
ImageGadget(0,0,0,0,0,ImageID(img))
HideWindow(0,0)
Repeat:E=WaitWindowEvent():Delay(5):Until(E=#PB_Event_CloseWindow):End
Posted: Sun Oct 07, 2007 7:36 pm
by Ollivier
Venit... vidit... Et vicit...

Posted: Mon Oct 15, 2007 7:40 pm
by hss
netmaestro, which graphic software did you use to convert to TIFF?
i'm using Fireworks CS3 - saving as TIFF 32 ...only about 30kb, then.
alphablending is ok, when viewing the image somewhere ...but with
your first code snippet, alphablending is *gone*..
thanks.
edit: photoshop..
#2 edit: YAY! by using The Gimp and makin' LZW everything works
and it's s-s-small.
Posted: Tue May 13, 2008 7:46 pm
by SofT MANiAC