[pygtk] gtk.gdk.Pixbuf troubles and IRC

Tim Evans t.evans at aranz.com
Wed Jul 21 06:20:51 WST 2010


On 2010-07-21 5:12, Andrew wrote:

>> #!/usr/bin/env python
>> import gtk
>> from gtk import gdk as gdk
>>
>> small = 16
>> counter = 0
>> offset = 4
>> large = 24
>>
>> if __name__ == "__main__":
>>
>>      icon_theme = gtk.icon_theme_get_default();
>>
>>      small_pixbuf = icon_theme.load_icon("image", small, ());
>>
>>      large_pixbuf = icon_theme.load_icon("image", large, ());
>>
>>      large_pixbuf.fill(0x000000);
>>
>>      small_pixbuf_buffer = small_pixbuf.copy()
>>      small_pixbuf.composite(large_pixbuf, 0, 0, 24, 24, 0, 0, 1, 1,
>> gdk.INTERP_NEAREST, 255);
>>      small_pixbuf_buffer = small_pixbuf.copy()
>>      small_pixbuf.composite(large_pixbuf, 0, 0, 24, 24, 4, 4, 1, 1,
>> gdk.INTERP_NEAREST, 255);
>>      small_pixbuf_buffer = small_pixbuf.copy()
>>      small_pixbuf.composite(large_pixbuf, 0, 0, 24, 24, 8, 8, 1, 1,
>> gdk.INTERP_NEAREST, 255);
>>
>>      window = gtk.Window()
>>      image = gtk.Image()
>>      image.set_from_pixbuf(large_pixbuf)
>>      window.add(image)
>>      window.show_all()
>>      window.connect("delete-event", gtk.main_quit)
>>      gtk.main()
>>
>
> Sorry to BUMP this guys but does anyone have any idea why this is
> happening, your reply doesn't have to be a fix. Any bugs/documentation
> you can point me to?
>

Make doubly sure that both the large and small pixbufs have an alpha 
channel.

Don't specify a destination rectangle larger than the scaled source 
pixbuf. That seems to pull in random data rather than blank space.

The following seems to work for me:

   large = gtk.gdk.Pixbuf('rgb', True, 8, 30, 30)
   large.fill(0)
   small = widget.render_icon('gtk-ok', 'button') # 20-by-20
   assert large.get_has_alpha()
   assert small.get_has_alpha()
   small.composite(large, 0, 0, 20, 20, 0, 0, 1, 1, 'nearest', 255)
   small.composite(large, 5, 5, 20, 20, 5, 5, 1, 1, 'nearest', 255)
   small.composite(large, 10, 10, 20, 20, 10, 10, 1, 1, 'nearest', 255)
   large.save('test.png', 'png')

-- 
Tim Evans
Applied Research Associates NZ
http://www.aranz.com/


More information about the pygtk mailing list