Re: Drawing bit mapped image in drawing area



On 27 March 2014 14:10, Ken Bass <daytooner gmail com> wrote:
I have a bit mapped image (really a video frame) that I want to display. I
am guessing that putting it into a user drawing box would be the way to go.
If there is a better way, please point me in that direction.

I have a tiny program which displays a live video image with an
overlay. It's in Python for gtk2, but gtk3 is (almost) the same,
except for the drawing model for the overlay. It runs at about 50fps
with not too much CPU load on my laptop.

https://github.com/jcupitt/rtiacquire/blob/master/rtiacquire/preview.py

The overlay is a crop box you can drag about and resize.

Use GtkImage to display the image data. When a new frame comes in,
decode to a RGB buffer, wrap it up as a GdkPixbuf, and set that pixbuf
as the data for the GtkImage.

https://developer.gnome.org/gdk-pixbuf/stable/gdk-pixbuf-Image-Data-in-Memory.html#gdk-pixbuf-new-from-data

https://developer.gnome.org/gtk3/stable/GtkImage.html#gtk-image-set-from-pixbuf

To draw the overlay, attach to expose-event with connect_after and
just draw. Your code will run after the GtkImage has painted the image
background, so draw anything you like and it'll float on top of the
image.

John


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]