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 Nov 26, 2014 9:30 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: re-sizing and re-scaling GdkPixBuf
PostPosted: Fri Dec 28, 2012 9:33 pm 
Offline
Familiar Face

Joined: Tue Dec 25, 2012 7:14 pm
Posts: 5
Hello everyone

I have been googling for 2 hours and i've gotten nowhere. I really need to solve this issue so I'm hoping that someone will be able to help me

I am making a C program that, for now, displays images (GdkPixbuf) in a drawingarea. Since the image sizes vary alot, I would like to automatically re-size it to the size of the drawing area.

Here is my code (Right now it draws the image in the left upper corner of the drawing area, and if the image is bigger, it gets cropped)

Code:
int start_clicked() //callback function that is executed when I hit start button
{

  gint n;
  GdkPixbuf * pix;
 

  GtkWidget *da=GTK_WIDGET(gtk_builder_get_object(builderG, "drawingarea1"));
 
 
  guint nFiles = g_slist_length(FilesPath); //FilesPath is a global var containing the paths of all the images to be processed
  PathList  paths[nFiles]; //struct where I'll put the pathnames (this is actually unnecessary but I got bigger issues right now :P)
 
  for (n=0; n<nFiles;n++)
  {
    paths[n].number=n;
    paths[n].filename=g_slist_nth_data(FilesPath,n);
    printf("%d - %s\n",paths[n].number,paths[n].filename); //just prints out every filepaths
    pix=LoadRawImage(paths[n].filename); //function defined bellow. It loads images from file
    gdk_draw_pixbuf(da->window,NULL,pix,0,0,0,0,-1,-1,GDK_RGB_DITHER_NONE,0,0);

   
  }
 
  return 1;
}


GdkPixbuf * LoadRawImage(char * path)
{
  static GdkPixbuf *pix;
 
  GError *erro=NULL;
 
  pix=gdk_pixbuf_new_from_file(path, &erro);
   
 
  if(!pix){g_print("An error occurred\n"); return pix;}
 
return pix;
 
}


Is there any way to resize the image?

Thanks


Top
 Profile  
 
 Post subject: Re: re-sizing and re-scaling GdkPixBuf
PostPosted: Sat Dec 29, 2012 12:36 am 
Offline
Familiar Face

Joined: Tue Dec 25, 2012 7:14 pm
Posts: 5
Problem solved. I realized how to re-size the image.

But now I'm having an hard time finding the current dimensions of the drawingarea. Any ideas?


Top
 Profile  
 
 Post subject: Re: re-sizing and re-scaling GdkPixBuf
PostPosted: Sat Dec 29, 2012 1:15 am 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
gtk_widget_get_allocation http://developer.gnome.org/gtk3/3.2/GtkWidget.html#gtk-widget-get-allocation. Works in both gtk2 and gtk3.
Incidentally you might want to look into cairographics. It is the standard drawing interface for gtk.


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: Google [Bot] and 2 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