GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Wed Sep 03, 2014 4:43 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: How to create a GdkImage from a "file".
PostPosted: Wed Dec 20, 2006 2:25 pm 
Offline
Familiar Face

Joined: Fri Dec 08, 2006 6:44 am
Posts: 11
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.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 20, 2006 6:42 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
You have to create the GtkImage first...

Code:
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:
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);

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 21, 2006 7:30 am 
Offline
Familiar Face

Joined: Fri Dec 08, 2006 6:44 am
Posts: 11
Micah Carrick wrote:
You have to create the GtkImage first...

Code:
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:
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.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 21, 2006 8:51 am 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
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:
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:
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:
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.

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google Adsense [Bot], ldries46 and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group