GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sun Oct 26, 2014 1:04 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Problem in saving the pixbuf to image when window is resized
PostPosted: Thu Nov 03, 2011 3:04 pm 
Offline
Familiar Face

Joined: Sat Jun 11, 2011 4:30 am
Posts: 7
Hi,
We are trying to save the pixbuf to an image.
We are facing an issue when we try to save the pixbuf after resizing the window.
Here is the code snippet.
I have also attached the screen shots of the window and the images that gets saved.
Code:
    _theCanvas= getWidget(GRAPH_CANVAS);// get the GtkDrawingArea from glade XML
    gtk_widget_set_app_paintable( _theCanvas, TRUE);
    gtk_widget_set_double_buffered( _theCanvas, FALSE);

    int canvasWidth= 0;
    int canvasHeight= 0;
    GError *error=NULL;

    gdk_drawable_get_size( gtk_widget_get_window( _theCanvas), &canvasWidth, &canvasHeight);
    std::cout<<"Height: "<<canvasHeight<<"Width: "<<canvasHeight<<std::endl;

    GdkPixbuf *pixbuf= gdk_pixbuf_get_from_drawable( NULL,
                                _theCanvas->window,
                                NULL,
                                0, 0, 0, 0,
                                canvasWidth,
                                canvasHeight);
    GdkPixbuf *rotatedPixbuf= gdk_pixbuf_rotate_simple( pixbuf, GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE);
    gdk_pixbuf_save( rotatedPixbuf, "/suhas/png/temp.png", "png", &error, NULL, "100", NULL);


Normal Window without Resizing
Attachment:
File comment: This is a Gtk Window without resizing, I am able to successfully save the image.
normal_window.JPG
normal_window.JPG [ 52.53 KiB | Viewed 200 times ]

This is how the image is saved.This is how we want even when the window is resized.
Attachment:
File comment: This is how the image gets saved.
normal_image.png
normal_image.png [ 14.27 KiB | Viewed 200 times ]

Resized Gtk window and the corresponding saved image screen shot
Attachment:
resized.jpg
resized.jpg [ 97.48 KiB | Viewed 200 times ]


Top
 Profile  
 
 Post subject: Re: Problem in saving the pixbuf to image when window is res
PostPosted: Fri Nov 04, 2011 3:10 am 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
Your trouble is you are only saving the window rather than the underlying image. Because you are using scrolled windows these are different sizes. If you check the documentation for gdk_pixmap_get_from_drawable http://developer.gnome.org/gdk/stable/gdk-Pixbufs.html#gdk-pixbuf-get-from-drawable you'll see that it is undefined in regions that are offscreen or obscured.

There are two approaches to solve your problem
1. Don't use scrollbars.
2. Save your image based on the data that generates the image on the screen rather than transferring the image on the screen to file.

Of course the second approach is better. If you draw from the screen you will always be limited in the size/resolution that the screen provides, but why should you have to be? You have a data set that creates a graph that is rendered to the screen at a specific size/resolution. Why not bypass the screen and render directly to file? GTK now uses cairo for rendering 2D graphics http://cairographics.org/ so you can almost forget about GDK. It's worth your while to learn it. With it you can directly render to SVG, PNG, etc images and specify a resolution/size.
To get a few ideas you could have a look at a plotting program I've been putting together https://github.com/pchilds/GtkPlot. It's fairly big but runs fast so it will run smoothly when churning through large data sets. If you compile it there's an example program that'll show you it working. (by the way I am interested in developing it for a wide range of scientific data presentation so if you are interested let me know any feedback on what features you need -- I notice that you've got a doubled y scale, I'll be working on incorporating that into the program in time)

Incidently don't use gdk_drawable_get_size. It's depreciated (http://developer.gnome.org/gdk/stable/gdk-Drawing-Primitives.html#gdk-drawable-get-size) so you'll run into trouble later on trying to maintain your code.


Top
 Profile  
 
 Post subject: Re: Problem in saving the pixbuf to image when window is res
PostPosted: Mon Nov 07, 2011 5:48 am 
Offline
Familiar Face

Joined: Sat Jun 11, 2011 4:30 am
Posts: 7
Thanks a lot for you help.


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 5 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