View Single Post
Posts: 437 | Thanked: 90 times | Joined on Nov 2006
#3
Hello, and thanks for finding the time to reply. I managed to draw on the image by: loading it as a pixbuf, getting the pixmap from that pixbuf, drawing on the pixmap and then creating a gtk.Image from the pixmap. Not elegant (horribly inelegant in fact) but seems to work. If only people documented this sort of thing better!

Thus, my (possibly optimisable) code reads:
Code:
pixbuf = gtk.gdk.pixbuf_new_from_file("image.png")
pixmap,mask = pixbuf.render_pixmap_and_mask()
cm = pixmap.get_colormap()
red = cm.alloc_color('red')
gc = pixmap.new_gc(foreground=red)
pixmap.draw_rectangle(gc, False, x, y, w, h)
image = gtk.Image()
image.set_from_pixmap(pixmap, mask)
(Just in case anyone has the same problem... it took me hours to find the solution online!)
 

The Following 3 Users Say Thank You to convulted For This Useful Post: