Question

I'm presently playing with gtk.pixbuf in python. In the API, the subpixbuf function is described as returning a pixbuf that shares data with the original pixbuf :

The subpixbuf() method creates a new gtk.gdk.Pixbuf that represents a sub-region of the pixbuf. The new pixbuf shares its pixels with the original pixbuf, so writing to one affects both.

But...

when I'm trying to divide a pixbuf in a list of subpixbuf and assign a value to each item, the original pixbuf stays the same.

animation.subpixbuf=[]
animation.pixbuf.fill(self.LIGHT_SQ_COLOR)
for i in range(64) :
   animation.subpixbuf += [animation.pixbuf.subpixbuf((7-i%8)*self.sq_width (i/8)*self.sq_width,w,w)]
   animation.subpixbuf[i]=self.squares[63-i]

Any ideas on how to compose a pixbuf from a bunch of subpixbufs ?

Thanks.

Était-ce utile?

La solution

When you do animation.subpixbuf[i]=self.squares[63-i], you're assigning subpixbuf[i] to a new Pixbuf object. You're not changing the Pixbuf previously stored in subpixbuf[i].

To do what you want to do you should take a look at the copy_area method of the Pixbuf class.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top