; Module/File: Pixbuf_SetAlpha.pb ; Function: Set alpha channel for pixbuf (optional with color) - Linux ; Author: Omi ; Date: Jun. 18, 2016 ; Version: 0.1 ; Target Compiler: PureBasic 5.22/5.31/5.4 ; Target OS: Linux: (X/K/L)ubuntu, Mint, 32/64, Ascii/Uni ;-------------------------------------------------------------- ;System icon are loaded by name as pixbufs (same as ImageID(#Image) and can be used everywhere, ImageID(#Image) is used. ;If Icon doesn't exist, '0' is returned and no Image is used -> NO CRASH !!! :-) EnableExplicit ;UsePNGImageDecoder(); :-) ImportC "" gdk_pixbuf_get_has_alpha(*pixbuf) ; gdk_pixbuf_new_from_file(filename.p-utf8, *error.GError) gdk_pixbuf_new_from_file_at_size(filename.p-utf8, width, height, *error.GError) gdk_pixbuf_add_alpha(*pixbuf, substitute_color, r, g, b) EndImport Enumeration GtkIconLookupFlags #GTK_ICON_LOOKUP_ALL = 0; Not gtk-defined, own constant to clearify #GTK_ICON_LOOKUP_NO_SVG = 1 #GTK_ICON_LOOKUP_FORCE_SVG = 2 #GTK_ICON_LOOKUP_USE_BUILTIN = 4 #GTK_ICON_LOOKUP_GENERIC_FALLBACK = 8 #GTK_ICON_LOOKUP_FORCE_SIZE = 16 EndEnumeration ; Object constants #Win_Main = 0 Global.i gEvent, gEventWin, gQuit Global.s gIconname= "axes.png" Global.i gBPS, gW, gH Global *gPixbuf, *gDPixbuf1, *gDPixbuf2, *gDPixbuf3, *gDPixbuf4 Procedure Pixbuf_LoadAndSizeFromName(FName.s, Width, Height) Protected *error.GError Protected w, h Protected *pixbuf= gdk_pixbuf_new_from_file_at_size(FName, Width, Height, @*error) If *error : Debug FName + ": " + PeekS(*error\message, -1, #PB_UTF8) : EndIf ProcedureReturn *pixbuf EndProcedure Procedure Create_WinMain() If OpenWindow(#Win_Main, 300, 200, 550, 240, "Add pixbuf alpha ...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) SetWindowColor (#Win_Main, $DFFFFF) *gPixbuf= Pixbuf_LoadAndSizeFromName(#PB_Compiler_Home + "/examples/3d/Data/Textures/" + gIconname, 64, 64) TextGadget (#PB_Any, 5, 5, 500, 22, "Add alpha channel and set transparent color to pixbuf ...") TextGadget (#PB_Any, 5, 35, 340, 22, "Original ImageGadget w/o alpha '" + gIconname + "'") ImageGadget (0, 360, 30, 64, 64, *gPixbuf) If Not gdk_pixbuf_get_has_alpha(*gPixbuf) TextGadget (#PB_Any, 5, 170, 150, 22, "Add alpha") *gDPixbuf1= gdk_pixbuf_add_alpha(*gPixbuf, #False, 0, 0, 0) ImageGadget (1, 120, 100, 64, 64, *gDPixbuf1, #PB_Image_Border) *gDPixbuf2= gdk_pixbuf_add_alpha(*gPixbuf, #True, 0, 0, 255) ImageGadget (2, 200, 100, 64, 64, *gDPixbuf2, #PB_Image_Border) *gDPixbuf3= gdk_pixbuf_add_alpha(*gPixbuf, #True, 0, 255, 0) ImageGadget (3, 280, 100, 64, 64, *gDPixbuf3, #PB_Image_Border) *gDPixbuf4= gdk_pixbuf_add_alpha(*gPixbuf, #True, 255, 0, 0) ImageGadget (4, 360, 100, 64, 64, *gDPixbuf4, #PB_Image_Border) TextGadget (#PB_Any, 120, 170, 80, 40, "w/o transp. color") TextGadget (#PB_Any, 200, 170, 80, 40, "w. transp. blue") TextGadget (#PB_Any, 280, 170, 80, 40, "w. transp. green") TextGadget (#PB_Any, 360, 170, 80, 40, "w. transp. red") Else TextGadget (#PB_Any, 5, 160, 200, 22, "No alpha channel -> no saturation") EndIf EndIf EndProcedure Create_WinMain() Repeat gEvent= WaitWindowEvent() Select gEvent Case #PB_Event_CloseWindow gQuit= #True EndSelect Until gQuit ; IDE Options = PureBasic 5.45 LTS (Linux - x86) ; CursorPosition = 49 ; Folding = - ; EnableUnicode ; EnableXP