Re: How to create a GdkImage from a file.
- From: muppet <scott asofyet org>
- To: Prasanna Kumar K <prasanna tataelxsi co in>
- Cc: gtk-devel-list gnome org
- Subject: Re: How to create a GdkImage from a file.
- Date: Wed, 20 Dec 2006 09:51:56 -0500
Please direct questions like this to gtk-app-devel-
list gnome org ... gtk-devel-list is for discussion of the
development *of* gtk+, not *with* it.
On Dec 20, 2006, at 8:35 AM, Prasanna Kumar K wrote:
I want to genetate a GdkImage from a file .. (so that this GdkImage
can be passed to gdk_draw_image())
I used following calls..
GtkImage *gtk_image = NULL;
GdkImage *gdk_image = NULL;
GdkBitmap *gdk_bitmap = NULL;
gtk_image_set_from_file (gtk_image, "1.jpg");
gtk_image_set_from_image (gtk_image, gdk_image, gdk_bitmap);
gdk_draw_image (pixmap, widget->style->white_gc, gdk_image,
0, 0, 60, 60, 100, 100);
but while running the appliction I'm getting following error..
Gtk-CRITICAL **: gtk_image_set_from_file: assertion `GTK_IS_IMAGE
(image)' failed
can anyone tell what is the problem.
Firstly, you're passing NULL for the image to set_from_image(); it
doesn't like that.
GtkImage != GdkImage. GtkImage is a widget that displays images.
GdkImage is basically a wrapper for XImage, which is a client-side
image resource.
You're also calling set_image() instead of get_image(). You could do
this sort of thing:
gtk_image_set_from_file (gtk_image, filename);
gtk_image_get_image (gtk_image, &gdk_image, &mask);
but that's very wasteful, using the GtkImage just to perform I/O for
you.
Instead, I think what you actually want is to use a GdkPixbuf, which
is a 24-bit client-side resource that is easier to use than
GdkImage. It goes something like this:
GdkPixbuf * pixbuf;
GError * error = NULL;
pixbuf = gdk_pixbuf_new_from_file ("1.jpg", &error);
if (pixbuf) {
gdk_draw_pixbuf (pixmap, widget->style->fg_gc, pixbuf,
0, 0, dest_x, dest_y,
gdk_pixbuf_get_width (pixbuf),
gdk_pixbuf_get_height (pixbuf,
GDK_RGB_DITHER_NORMAL,
dest_x, dest_y);
} else {
/* error contains failure info */
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]