Page 1 of 1
gdk pixbuf
Posted: Tue Feb 27, 2007 10:25 pm
by Trond
Why doesn't this work? If the image id givgen to the imagegadget is invalid it should give a debugger error, else it should work?
Code: Select all
ImportC "/usr/lib/libgdk_pixbuf-2.0.so"
gdk_pixbuf_new_from_file(Filename.s, *Error.Long)
EndImport
Import "/usr/lib/libglib-2.0.so"
EndImport
Import "/usr/lib/libgobject-2.0.so"
EndImport
Import "/usr/lib/libgmodule-2.0.so"
EndImport
Import "/usr/lib/libpng.so"
EndImport
Import "/usr/lib/libjpeg.so"
EndImport
Import "/usr/lib/libtiff.so"
EndImport
Import "/usr/lib/libz.so"
EndImport
Import "/usr/lib/libm.so"
EndImport
#APPNAME = ""
#WndMain = 0
OpenWindow(#WndMain, 0, 0, 640, 480, #APPNAME, #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget | #PB_Window_SizeGadget | #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
CreateGadgetList(WindowID(#WndMain))
img = gdk_pixbuf_new_from_file("/usr/share/pixmaps/terminal.xpm", @a)
Debug img
ImageGadget(0, 10, 10, 100, 100, img)
Repeat
Select WaitWindowEvent()
Case #PB_Event_Gadget
Case #PB_Event_CloseWindow
Break
EndSelect
ForEver
g_object_unref_(img)
Posted: Wed Feb 28, 2007 12:10 am
by walker
I'm at the same problem atm.... solved the loading... you must define the error variable prior to the first use...
in your case a a.l would do (and make sure the image exists.... the used terminal.xpm isn't installed on my computer...just a hint....)
after that you should get img <> 0 and a=0 (no error).... but the imagegadget doesn't shows the image... It seems, that this imageID isn't valid for PB....
The imageID 0 is valid for the imagegadget... even if there is no loaded image (this is verified by load/catch image and you'll get a debugger warning) and very usefull when creating a gadget without a imgage.... to verify if it is a valid image, I always use IsImage()....
Maybe Fred/Freak could give us an answer?
Posted: Wed Feb 28, 2007 3:35 am
by freak
The gadget expects a GdkPixmap (that is what ImageID() returns), not a GdkPixbuf.
So either convert your pixbuf to a pixmap, or use something like
gtk_image_set_from_pixbuf_(GadgetId(#ImageGadget), pixbuf) to apply a pixbuf to the gadget.
(there is even a gtk_image_set_from_file() btw).
The debugger cannot know if what you pass is a pixbuf or a pixmap, and simply throwing an
error for any non PB created image is not helpful either.
Posted: Wed Feb 28, 2007 10:20 am
by walker
freak wrote:The gadget expects a GdkPixmap (that is what ImageID() returns), not a GdkPixbuf.
THAT was it..... thanks for the hint

Posted: Wed Feb 28, 2007 10:41 am
by Trond
Ok thanks.
Posted: Wed Feb 28, 2007 4:00 pm
by Trond
If I use the gtk_image_set_from_pixbuf_() function it works fine with ImageGadgets, but it doesn't work for ListIconGadgets (I used GadgetItemID()). If I convert it first and pass it to AddGadgetItem() it gets some ugly random background. Is this because I'm converting it wrong or because PB does something to the alpha channel?
I can get the alpha channel from the conversion, but it's no use if it's not in the pixmap.
Code: Select all
ImportC "/usr/lib/libgdk_pixbuf-2.0.so"
gdk_pixbuf_new_from_file.l(Filename.s, *Error.Long)
gdk_draw_pixbuf.l(GdkDrawable, GdkGC, GdkPixbuf, src_x, src_y, dest_x, dest_y, width, height, dither, x_dither, y_dither)
gdk_pixbuf_render_pixmap_and_mask(GdkPixbuf, pixmap_return, mask_return, alpha_threshold)
EndImport
Import "/usr/lib/libglib-2.0.so"
EndImport
Import "/usr/lib/libgobject-2.0.so"
EndImport
Import "/usr/lib/libgmodule-2.0.so"
EndImport
Import "/usr/lib/libpng.so"
EndImport
Import "/usr/lib/libjpeg.so"
EndImport
Import "/usr/lib/libtiff.so"
EndImport
Import "/usr/lib/libz.so"
EndImport
Import "/usr/lib/libm.so"
EndImport
OpenWindow(0, 0, 0, 640, 480, "", #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget | #PB_Window_SizeGadget | #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
CreateGadgetList(WindowID(0))
img = gdk_pixbuf_new_from_file("/usr/share/pixmaps/abiword.png", @a)
gdk_pixbuf_render_pixmap_and_mask(img, @pixmap, 0, 255)
ListIconGadget(0, 10, 10, 620, 260, "", 10)
AddGadgetItem(0, 0, "Hello", pixmap)
g_object_unref_(img)
Repeat
Select WaitWindowEvent()
Case #PB_Event_Gadget
Case #PB_Event_CloseWindow
Break
EndSelect
ForEver
Re: gdk pixbuf
Posted: Wed Nov 21, 2012 10:19 am
by Shardik
freak wrote:The gadget expects a GdkPixmap (that is what ImageID() returns), not a GdkPixbuf.
This has changed with PB 4.40:
http://www.purebasic.fr/blog/?p=196PureBasic Team Blog wrote:One thing to note in general is that PB images are now GdkPixbuf objects and no longer GdkPixmap. This is a big improvement as many Gtk functions expect GdkPixbuf nowadays, so it is actually easier to use PB images with Gtk functions.
Therefore it is now a lot easier to display for example XPM images in a ListView:
Code: Select all
EnableExplicit
#DirPath = "/usr/share/pixmaps"
ImportC "-lgdk_pixbuf-2.0"
gdk_pixbuf_new_from_file.l(Filename.S, *Error.GError)
EndImport
Define Filename.S
Define ImageID.I
Procedure.I LoadXPMImage(Filename.S)
Protected *Error.GError
Protected ImageID.I
ImageID = gdk_pixbuf_new_from_file(#DirPath + "/" + Filename, @*Error)
If ImageID = 0
Debug *Error\message
EndIf
ProcedureReturn ImageID
EndProcedure
OpenWindow(0, 270, 100, 250, 590, "XPM Images")
ListIconGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 20, "XPM Filename", WindowWidth(0) - 46)
gtk_tree_view_set_headers_visible_(GadgetID(0), #False)
If ExamineDirectory(0, #DirPath, "*.xpm") = 0
Debug "Error examining directory " + #DirPath
End
EndIf
While NextDirectoryEntry(0)
Filename = DirectoryEntryName(0)
ImageID = LoadXPMImage(Filename)
If ImageID = 0
AddGadgetItem(0, -1, Filename)
Else
AddGadgetItem(0, -1, Filename, ImageID)
EndIf
Wend
FinishDirectory(0)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow