开发者

display an image in gtk - is gtk drawing area required?

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开发者_JAVA百科 the window? Another option would be to use cairo. Can anyone please suggest a good way to do it?


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜