Image transparency on a PureBasic form

Everything else that doesn't fall into one of the other PB categories.
PBJim
Enthusiast
Enthusiast
Posts: 296
Joined: Fri Jan 19, 2024 11:56 pm

Image transparency on a PureBasic form

Post by PBJim »

Would someone mind confirming if LoadImage() and ImageGadget() support the concept of transparency and if JPG transparency is supported? I can't seem to find an example image to try and there doesn't appear to be much in the way of reference to this, other than briefly in the documentation that says it isn't supported for BMPs. Thanks.

Code: Select all

EnableExplicit

UseJPEGImageDecoder()

Define Window_0 = OpenWindow(#PB_Any, #PB_Ignore, #PB_Ignore, 590, 240, "Test Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

Define Button_0 = ButtonGadget(#PB_Any, 40, 170, 130, 25, "Update", #PB_Button_Default)
Define Button_1 = ButtonGadget(#PB_Any, 190, 170, 130, 25, "Cancel")

Define Img_Window_0_0   = LoadImage(#PB_Any,"MyImage.JPG")
Define Image_0          = ImageGadget(#PB_Any, 360, 20, 193, 84, ImageID(Img_Window_0_0))

Define event

Repeat
  event = WaitWindowEvent()
  
  Select event
    Case #PB_Event_CloseWindow
      
    Case #PB_Event_Gadget
      Select EventGadget()
        Case Button_0
          
        Case Button_1
          End
          
      EndSelect
  EndSelect
  
ForEver

CloseWindow(Window_0)
BarryG
Addict
Addict
Posts: 4173
Joined: Thu Apr 18, 2019 8:17 am

Re: Image transparency on a PureBasic form

Post by BarryG »

I don't know about JPGs, but you can certainly load and use transparent ICOs and PNGs easily. Transparent BMPs are done like this:

Code: Select all

; Note: Palette index 1 of the BMP file is the transparency color.
OpenWindow(0,200,200,320,120,"test",#PB_Window_SystemMenu)
hbitmap=LoadImage_(0,"Transparent BMP.bmp",#IMAGE_BITMAP,0,0,#LR_LOADFROMFILE|#LR_LOADTRANSPARENT|#LR_LOADMAP3DCOLORS)
ImageGadget(0,10,10,300,100,hbitmap)
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
BMP version source -> https://www.purebasic.fr/english/viewtopic.php?t=2564
User avatar
jacdelad
Addict
Addict
Posts: 2010
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: Image transparency on a PureBasic form

Post by jacdelad »

There is no thing like jpeg-transparency...
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
PBJim
Enthusiast
Enthusiast
Posts: 296
Joined: Fri Jan 19, 2024 11:56 pm

Re: Image transparency on a PureBasic form

Post by PBJim »

Thanks BarryG, I think I'll just need to try it when I receive the logo JPEG file. It sounds like it's going to be okay though.
PBJim
Enthusiast
Enthusiast
Posts: 296
Joined: Fri Jan 19, 2024 11:56 pm

Re: Image transparency on a PureBasic form

Post by PBJim »

Indeed, just confirmed with a trusty old copy of Jasc Paint Shop Pro, that JPG doesn't offer transparency, but PNG is fine.
Post Reply