transparent png on window.

Just starting out? Need help? Post your questions and find answers here.
hss
User
User
Posts: 69
Joined: Thu Mar 08, 2007 6:02 pm

transparent png on window.

Post 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:
Image

..something wrong with the API?

love,
hss


edit: here's the PNG - http://img210.imageshack.us/img210/3071/ssqt6.png
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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.
BERESHEIT
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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.
BERESHEIT
hss
User
User
Posts: 69
Joined: Thu Mar 08, 2007 6:02 pm

Post 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..
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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
BERESHEIT
Ollivier
Enthusiast
Enthusiast
Posts: 281
Joined: Mon Jul 23, 2007 8:30 pm
Location: FR

Post by Ollivier »

Venit... vidit... Et vicit... :D
hss
User
User
Posts: 69
Joined: Thu Mar 08, 2007 6:02 pm

Post 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.
SofT MANiAC
Enthusiast
Enthusiast
Posts: 142
Joined: Mon Sep 17, 2007 10:28 am
Location: P.O.P
Contact:

Post by SofT MANiAC »

POiNT.OF.PRESENCE group
Post Reply