How do I load a PNG file with alpha channel?

BlitzMax Forums/BlitzMax Beginners Area/How do I load a PNG file with alpha channel?

Well,

please find below screen shots of my various tests under WinXP, MacOSX and Linux - always using the latest BlitzMax with synchronized modules.

The GIF and PNG versions of the BlitzMax-Logo are shown below:

(GIF version)
(PNG version)

WinXP-Screenshot:



(don't let yourself be misleaded by the "transparent" appearance of the .bmp image - the background color has just been chosen properly in order to produce that effect. What's more important: obviously, PNG alpha channel does not work)

MacOSX-Screenshot:


(not bad - although the ".bmp" breaks as soon as you force a repaint. Additionally, the "dividers" do not appear which is rather bad)

Linux-Screenshot:



(how poor, nothing works, neither .bmp display nor PNG transparency)

And here is the source code of my little program:

import BRL.BMPLoader
import BRL.PNGLoader

Local MainWindow:TGadget = CreateWindow:TGadget("PixmapAlphaTest - are PNGs & GIFs with Alpha Channel supported?",364,36,320,210,NULL,WINDOW_TITLEBAR|WINDOW_RESIZABLE |WINDOW_CLIENTCOORDS )
    SetStatusText( MainWindow:TGadget, "(no special action required)" )
    Local BMPView:TGadget = CreatePanel:TGadget(27,54,32,32,MainWindow:TGadget,Null,"")
      Local Pixmap_BMPView:TPixmap = LoadPixmap:TPixmap ( "BlitzMAX-Logo_32x32.bmp" )
      SetPanelPixmap( BMPView:TGadget , Pixmap_BMPView:TPixmap ,1 )
      SetGadgetLayout( BMPView:TGadget,EDGE_ALIGNED,EDGE_CENTERED,EDGE_ALIGNED,EDGE_CENTERED )
    Local UpperSeparator:TGadget = CreatePanel:TGadget(2,40,316,2,MainWindow:TGadget,PANEL_BORDER,"")
      Local Pixmap_UpperSeparator:TPixmap = LoadPixmap:TPixmap ( "sunkenLine.png" )
      SetPanelPixmap( UpperSeparator:TGadget , Pixmap_UpperSeparator:TPixmap ,0 )
    Local IconView:TGadget = CreatePanel:TGadget(2,4,32,32,MainWindow:TGadget,PANEL_ACTIVE,"")
      Local Pixmap_IconView:TPixmap = LoadPixmap:TPixmap ( "BlitzMax-Logo_32x32.bmp" )
      SetPanelPixmap( IconView:TGadget , Pixmap_IconView:TPixmap ,1 )
      SetGadgetLayout( IconView:TGadget,EDGE_ALIGNED,EDGE_CENTERED,EDGE_ALIGNED,EDGE_CENTERED )
    Local TitleLabel:TGadget = CreateLabel:TGadget("PixmapAlphaTest",36,2,282,18,MainWindow:TGadget,LABEL_RIGHT)
      SetGadgetLayout( TitleLabel:TGadget,EDGE_CENTERED,EDGE_ALIGNED,EDGE_ALIGNED,EDGE_CENTERED )
      Local Font_TitleLabel:TGuiFont = LoadGuiFont:TGuiFont( "Arial" , 12 , True , True , False )
      SetGadgetFont( TitleLabel:TGadget, Font_TitleLabel:TGuiFont )
    Local SubtitleLabel:TGadget = CreateLabel:TGadget("are PNGs & GIFs with Alpha Channel supported?",36,22,282,16,MainWindow:TGadget,LABEL_RIGHT)
      SetGadgetLayout( SubtitleLabel:TGadget,EDGE_CENTERED,EDGE_ALIGNED,EDGE_ALIGNED,EDGE_CENTERED )
      Local Font_SubtitleLabel:TGuiFont = LoadGuiFont:TGuiFont( "Arial" , 9 , True , False , False )
      SetGadgetFont( SubtitleLabel:TGadget, Font_SubtitleLabel:TGuiFont )
    Local LowerSeparator:TGadget = CreatePanel:TGadget(2,185,316,2,MainWindow:TGadget,PANEL_BORDER,"")
      Local Pixmap_LowerSeparator:TPixmap = LoadPixmap:TPixmap ( "sunkenLine.png" )
      SetPanelPixmap( LowerSeparator:TGadget , Pixmap_LowerSeparator:TPixmap ,0 )
      SetGadgetLayout( LowerSeparator:TGadget,EDGE_ALIGNED,EDGE_ALIGNED,EDGE_CENTERED,EDGE_ALIGNED )
    Local Statusbar:TGadget = CreateLabel:TGadget("(no special action required)",2,189,316,18,MainWindow:TGadget,Null)
      SetGadgetLayout( Statusbar:TGadget,EDGE_ALIGNED,EDGE_ALIGNED,EDGE_CENTERED,EDGE_ALIGNED )
      Local Font_Statusbar:TGuiFont = LoadGuiFont:TGuiFont( "Arial" , 8 , False , False , False )
      SetGadgetFont( Statusbar:TGadget, Font_Statusbar:TGuiFont )
    Local BMPLabel:TGadget = CreateLabel:TGadget("BlitzMax-Logo.bmp - no transparency",75,62,235,23,MainWindow:TGadget,Null)
      Local Font_BMPLabel:TGuiFont = LoadGuiFont:TGuiFont( "Arial" , 9 , True , False , False )
      SetGadgetFont( BMPLabel:TGadget, Font_BMPLabel:TGuiFont )
    Local GIFView:TGadget = CreatePanel:TGadget(27,98,32,32,MainWindow:TGadget,Null,"")
      Local Pixmap_GIFView:TPixmap = LoadPixmap:TPixmap ( "BlitzMAX-Logo_32x32.gif" )
      SetPanelPixmap( GIFView:TGadget , Pixmap_GIFView:TPixmap ,1 )
      SetGadgetLayout( GIFView:TGadget,EDGE_ALIGNED,EDGE_CENTERED,EDGE_ALIGNED,EDGE_CENTERED )
    Local GIFLabel:TGadget = CreateLabel:TGadget("BlitzMax-Logo.gif - with transparency",75,106,235,23,MainWindow:TGadget,Null)
      Local Font_GIFLabel:TGuiFont = LoadGuiFont:TGuiFont( "Arial" , 9 , True , False , False )
      SetGadgetFont( GIFLabel:TGadget, Font_GIFLabel:TGuiFont )
    Local PNGView:TGadget = CreatePanel:TGadget(27,142,32,32,MainWindow:TGadget,Null,"")
      Local Pixmap_PNGView:TPixmap = LoadPixmap:TPixmap ( "BlitzMAX-Logo_32x32.png" )
      SetPanelPixmap( PNGView:TGadget , Pixmap_PNGView:TPixmap ,1 )
      SetGadgetLayout( PNGView:TGadget,EDGE_ALIGNED,EDGE_CENTERED,EDGE_ALIGNED,EDGE_CENTERED )
    Local PNGLabel:TGadget = CreateLabel:TGadget("BlitzMax-Logo.png - with alpha channel",75,150,235,23,MainWindow:TGadget,Null)
      Local Font_PNGLabel:TGuiFont = LoadGuiFont:TGuiFont( "Arial" , 9 , True , False , False )
      SetGadgetFont( PNGLabel:TGadget, Font_PNGLabel:TGuiFont )

repeat
  waitEvent()
until (EventID() = EVENT_WINDOWCLOSE)


Hmmm, as you can see, I got the PNG transparency working under MacOSX only - and the GIF never shows up - meanwhile, I also tried several GIF files (without success) because my first impression was that my GIF file could be broken.