GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sat Dec 20, 2014 11:02 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: How to set size of gtk image?
PostPosted: Tue Aug 07, 2012 9:02 am 
Offline
Familiar Face

Joined: Tue Nov 29, 2011 7:59 pm
Posts: 11
Hello everyone!

In my program I insert images in table(1x4) cells like this:
Code:
for(i=0; i<=3; i++) {
image[i] = gtk_image_new_from_file("pic.png");
gtk_table_attach_defaults (GTK_TABLE(table_toimg), image[i], i, i+1, 0, 1);
}


But if I have image pic.png with size, for example 300x300 (width x height) I get in result row with size 1200x300, and I want to get row with size 400x100. How I can set (or change) image size?


Top
 Profile  
 
 Post subject: Re: How to set size of gtk image?
PostPosted: Tue Aug 07, 2012 11:29 am 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hi.

You'll need to load image manually at proper size and then create image widget. Updated code should look something like this:

Code:
for(i=0; i<=3; i++)
{
  GError *error = NULL;
  GdkPixbuf *pixbuf;

  pixbuf = gdk_pixbuf_new_from_file_at_size ("pic.png", 100, 100, &error);
  if (!pixbuf)
  {
    g_print ("Error: %s\n", error->message);
    g_error_free (error);
    /* Handle error here */
  }
 
  image[i] = gtk_image_new_from_pixbuf(pixbuf);
  g_object_unref (pixbuf);
  gtk_table_attach_defaults (GTK_TABLE(table_toimg), image[i], i, i+1, 0, 1);
}


Cheers,
Tadej


Top
 Profile  
 
 Post subject: Re: How to set size of gtk image?
PostPosted: Fri Aug 10, 2012 6:59 pm 
Offline
Familiar Face

Joined: Tue Nov 29, 2011 7:59 pm
Posts: 11
Thank you, tadeboro. It's what i really need


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

All times are UTC


Who is online

Users browsing this forum: No registered users 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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group