Question

I'm trying to display an image that I load from a pixbuf( from data in memory) and the image gets updated every time (as the pixbuf is also changing with time). My question is that since the window will only contain the image( which is being updated periodically) , do I need a gtk drawable or a drawing area for this? or can I simply display the image in the window? Another option would be to use cairo. Can anyone please suggest a good way to do it?

Was it helpful?

Solution

Load the file into a pixbuf, there is a new_from_file constructor or something for that.

Yes, create a DrawingArea and stick it in a Box or something somewhere.

Next, get the DrawingArea parent window (there will be a method like get_window or something for that). This will be your Drawable.

Create a GC (graphics context) - you dont need to set any special values in it.

Connect the DrawingArea to an expose event. In the expose event, have it call the draw_pixbuf method on the Drawable with your pixbuf with the GC you created.

Call this same draw_pixbuf method whenever you update the pixbuf somehow.

You may also want to consider using a pixmap instead, if you are not loading it from a file and intend to draw on it. A pixmap itself is a Drawable, so you can directly draw rectangles and things on it. The only real difference in displaying it on your DrawingArea is that you need to call the draw_drawable method instead of draw_pixbuf on the Drawable.

Note that I am writing this from memory of using Perl/Gtk2, and it may not map cleanly to whatever language you are using.

OTHER TIPS

A GtkImage will work just fine, and be simpler than all the things you listed ;-)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top