Re: Loading and displaying a jpeg image



I dont think you can #include a jpeg image, you can #include an xpm though - so
if you convert your image.jpg to image.xpm
in your file you can do this

#include <image.xpm>

that'll be a static char  *image_xpm[], you can modify its name by editing the
pixmap file itself.

then you create a pixmap for that

GdkPixmap *gdkpixmap;
GdkBitmap *gdkbitmap;
GdkColormap *colormap;
GtkPixmap *gtkpixmap; /* this is a widget */
colormap = gtk_widget_get_colormap(top_level_window) for example;
gdkpixmap = gdk_pixmap_colormap_create_from_xpm_d(NULL, colormap, &gdkbitmap,
NULL, image_xpm);
gtkpixmap = gtk_pixmap_new (gdkpixmap,gdkbitmap);
/* assuming you dont need them anymore - you should unref them */
gdk_pixmap_unref(gdkpixmap); 
gdk_bitmap_unref(gdkbitmap);
/* then you can pack it or add it to a container */
gtk_box_pack_start(GTK_BOX(somebox), gtkpixmap, FALSE, FALSE, 0);
or
gtk_container_add(GTK_CONTAINER(somecontainer), gtkpixmap);

- Now if you really want to keep it jpeg - you can use GdkPixbuf or Imlib, I'd
use Imlib2 since its out and stable now, here is waht you can do with Imlib2
(this is one of the ways)

Imlib_Image im;

im = imlib_load_image(path_to_image);
imlib_context_set_image(im);
imlib_context_set_drawable(GDK_WINDOW_XWINDOW(somewidgets->window));
and imlib_render_image_on_drawable(x,y);

You can make imlib render pixmaps for this image also so you can make a widget
out of the image also but you'd have to create foreign gdk_pixmaps since it
returns X pixmaps. So there is just about trizillion ways to do it :-)

Maher


On Sun, 22 Oct 2000 13:39:03 -0600, Jeff Shipman said:

> Does anybody know where I can find documentation and an
>  example for how to load and display a jpeg image in a box
>  or another widget? Preferably, I would like to compile it
>  into my program so it doesn't have to look for an external
>  file at runtime (and therefore isn't dependent on it
>  being in a certain location). Any help would be greatly
>  appreciated. Thanks.
>  
>  -- 
>  Jeff "Shippy" Shipman     E-Mail: shippy cs nmt edu
>  CS Major / EE Minor       ICQ: 1786493
>  New Mexico Institute of Mining and Technology
>  Homepage: http://www.nmt.edu/~shippy
>  
>  
>  _______________________________________________
>  gtk-list mailing list
>  gtk-list gnome org
>  http://mail.gnome.org/mailman/listinfo/gtk-list
>  
>  

-- 
muhri muhri net -- http://www.muhri.net





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]