How to resize gtk.gdk.Pixmap

654 views Asked by At

I am created an instance of gtk.gdk.Pixmap, and painted on it something. For example:

pixmap = gtk.gdk.Pixmap(widget.window,100,800)
pixmap.draw_rectangle(gc, True, 0, 0, 100, 800)
pixmap.draw_line(gc, 0, 0,100, 800)

How can I to resize the Pixmap? One way that I see is to copy the Pixmap into a PixBuf using gtk.gdk.Pixbuf.get_from_drawable, then resize the Pixbuf, and then copy the Pixbuf to the Pixmap

Is there any way to do this without all the copying?

2

There are 2 answers

0
plaes On BEST ANSWER

Unfortunately it's not possible without all this copying. Please note that GdkPixmap and GdkPixbuf are deprecated in favor of Cairo.

1
Federico Mena-Quintero On

Indeed, those are deprecated.

More importantly, GdkPixmap is a server-side resource - the contents of the pixmap live in the X server's memory. When you do get_from_drawable(), you are asking for those contents to be transferred to your application, which is expensive.

Instead, create a Cairo image suface, and do your drawing there. This is a client-side resource, so you won't get that performance penalty. Image surfaces can be scaled by drawing them to another surface with a suitable transformation.