Re: GDK-PixBuf
- From: Andrej Prsa <andrej prsa guest arnes si>
- To: Havoc Pennington <hp redhat com>
- Cc: gtk-list gnome org
- Subject: Re: GDK-PixBuf
- Date: Tue, 12 Jun 2001 14:21:49 +0200
Thank you very much, everybody!
> In GTK 2, you could just do:
> image = gtk_image_new_from_file ("test.jpg");
> gtk_container_add (GTK_CONTAINER (window), image);
>
> So look forward to that. ;-)
>
I am looking forward to that! In the meantime, since there's been a lot of questions on a working example for Gtk1.2, I'm posting my solution, hoping someone too will find it useful!
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "gtk/gtk.h"
#include "gdk-pixbuf/gdk-pixbuf.h"
GdkPixmap *picture;
static gint expose_event (GtkWidget *widget, GdkEventExpose *event)
{
gdk_draw_pixmap (widget->window, widget->style->fg_gc[GTK_WIDGET_STATE (widget)], picture, event->area.x, event->area.y, event->area.x, event->area.y, event->area.width, event->area.height);
return FALSE;
}
int main (int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *vbox;
GdkPixbuf *image;
GdkGC *setup;
GtkWidget *drawing_area;
gtk_init (&argc, &argv);
printf ("\n");
if (gdk_init_check (&argc, &argv) == 1) printf ("Connection to X Server Successful\n");
if (gdk_init_check (&argc, &argv) == 0) printf ("Connection to X Server Failed\n");
printf ("Display: %s\n", gdk_get_display () );
printf ("ScrWidth: %d\n", gdk_screen_width () );
printf ("ScrHeight: %d\n", gdk_screen_height () );
gtk_widget_push_visual (gdk_rgb_get_visual ());
gtk_widget_push_colormap (gdk_rgb_get_cmap());
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_signal_connect (GTK_OBJECT (window), "destroy", GTK_SIGNAL_FUNC (gtk_main_quit), "WM destroy");
gtk_widget_set_usize (window, 512, 512);
gtk_widget_pop_visual ();
gtk_widget_pop_colormap ();
vbox = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (window), vbox);
drawing_area = gtk_drawing_area_new ();
gtk_drawing_area_size (GTK_DRAWING_AREA (drawing_area), 512, 512);
gtk_box_pack_start (GTK_BOX (vbox), drawing_area, TRUE, TRUE, 0);
gtk_signal_connect (GTK_OBJECT (drawing_area), "expose_event",
(GtkSignalFunc) expose_event, NULL);
image = gdk_pixbuf_new_from_file ("test.gif");
picture = gdk_pixmap_new (NULL, 512, 512, gtk_widget_get_visual (drawing_area)->depth);
setup = gdk_gc_new (picture);
printf ("Visual: %d\n", gtk_widget_get_visual (drawing_area)->depth);
printf ("Channels: %d\n", gdk_pixbuf_get_n_channels (image));
printf ("Width: %d\n", gdk_pixbuf_get_width (image));
printf ("Height: %d\n", gdk_pixbuf_get_height (image));
printf ("Alpha: %d\n", gdk_pixbuf_get_has_alpha (image));
printf ("Bits: %d\n", gdk_pixbuf_get_bits_per_sample (image));
printf ("Rowstride: %d\n", gdk_pixbuf_get_rowstride (image));
printf ("\n");
gdk_pixbuf_render_to_drawable (image, picture, setup, 0, 0, 0, 0, 512, 512, GDK_RGB_DITHER_NONE, 0, 0);
gdk_draw_pixmap ((GdkDrawable *)drawing_area, setup, picture, 0, 0, 0, 0, 512, 512);
gtk_widget_show_all (window);
gtk_main();
return (0);
}
Thanks again!
Andrej
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]