GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to create a GdkImage from a "file".

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
kprasanna16
Familiar Face


Joined: 08 Dec 2006
Posts: 11

PostPosted: Wed Dec 20, 2006 2:25 pm    Post subject: How to create a GdkImage from a "file". Reply with quote

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.
Back to top
Micah Carrick
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 496
Location: Portland, OR USA

PostPosted: Wed Dec 20, 2006 6:42 pm    Post subject: Reply with quote

You have to create the GtkImage first...

Code: (Plaintext)
1
gtk_image_new_from_file (gtk_image, "1.jpg");


As far as your two calls... why are you calling this? You've already set the image by filename.
gdk_draw_image. I'm assuming you're trying to draw the image onto a GdkPixmap you have defined elsewhere named "pixmap"?

Try this maybe... (just guessing here):

Code: (Plaintext)
1
2
3
4
5
6
7
8
9
GtkImage *gtk_image = NULL;
GdkImage *gdk_image = NULL;

gtk_image_new_from_file (gtk_image, "1.jpg");
gtk_image_get_image (gtk_image, &gdk_image, NULL);

gdk_draw_image (pixmap, widget->style->white_gc, gdk_image,
0, 0, 60, 60, 100, 100);
Back to top
kprasanna16
Familiar Face


Joined: 08 Dec 2006
Posts: 11

PostPosted: Thu Dec 21, 2006 7:30 am    Post subject: Reply with quote

Micah Carrick wrote:
You have to create the GtkImage first...

Code: (Plaintext)
1
gtk_image_new_from_file (gtk_image, "1.jpg");


As far as your two calls... why are you calling this? You've already set the image by filename.
gdk_draw_image. I'm assuming you're trying to draw the image onto a GdkPixmap you have defined elsewhere named "pixmap"?

Try this maybe... (just guessing here):

Code: (Plaintext)
1
2
3
4
5
6
7
8
9
GtkImage *gtk_image = NULL;
GdkImage *gdk_image = NULL;

gtk_image_new_from_file (gtk_image, "1.jpg");
gtk_image_get_image (gtk_image, &gdk_image, NULL);

gdk_draw_image (pixmap, widget->style->white_gc, gdk_image,
0, 0, 60, 60, 100, 100);


Thank you for your help..
but gtk_image_new_from_file() is called as

gtk_image = gtk_image_new_from_file("1.jpg"); //here the return value should be GtkWidget
if I define gtk_image as [GtkWidget *gtk_image = NULL] it is giving waring as
warning: passing arg 1 of `gtk_image_get_image' from incompatible pointer type. as gtk_image_get_image() is expecting GtkImage as 1st argument
not GtkWidget.
while running the program I'm not getting any image and getting these errors...

(scribble-simple:2996): Gtk-CRITICAL **: gtk_image_get_image: assertion `image->storage_type == GTK_IMAGE_IMAGE || image->storage_type == GTK_IMAGE_EMPTY' failed

(scribble-simple:2996): Gdk-CRITICAL **: gdk_draw_image: assertion `image != NULL' failed

(scribble-simple:2996): Gdk-DirectFB-WARNING **: gdk_window_set_keep_above() not implemented.


(scribble-simple:2996): Gdk-DirectFB-WARNING **: gdk_window_set_keep_below() not implemented.
Back to top
Micah Carrick
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 496
Location: Portland, OR USA

PostPosted: Thu Dec 21, 2006 8:51 am    Post subject: Reply with quote

Okay... my bad. I just did that really quickly and didn't look closely at the return type. Furthermore, I believe gtk_image_new_from_file is loading a GTK_IMAGE_PIXBUF (GdkPixbuf). I haven't done muc with any of this... I'm just looking at the API-- I've never had to use much of the Gdk level image functions. But, could you use a GdkPixbuf instead? I can't really look into this thoroughly at the moment... but... it looks like you might be able to do something along the lines of:

Code: (Plaintext)
1
2
3
4
5
6

GdkPixbuf *gdk_pixbuf = NULL;

gdk_pixbuf = gdk_pixbuf_new_from_file  ("1.jpg", NULL); /* The NULL ignores errors */
gdk_draw_pixbuf (pixmap, widget->style->white_gc, gdk_image, 0, 0, 60, 60, 100, 100, GDK_RGB_DITHER_NONE, 0, 0);


If I may ask... what is this for? That is, what are you trying to achieve. I'm sure someone here could provide more help if we knew your overall objective.

PS.
The appropriate way to use the gtk_image_new_from_file function would have been:

Code: (Plaintext)
1
2
GtkWidget *gtk_image = NULL;
gtk_image = gtk_image_new_from_file ("1.jpg");


and then you could pass it to function requiring a GtkImage by casting it:

Code: (Plaintext)
1
hypothetical_function (GTK_IMAGE (gtk_image), "foobar");


The idea here is that you can declare any widget which is derived from the base class of GtkWidget as a GtkWidget and then cast it into the type needed by the function.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP