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