[pygtk] problems with image transparency and flipping
David Hugh-Jones
hughjonesd at yahoo.co.uk
Thu Jul 1 02:19:09 WST 2004
Replying to myself, in case it is useful in future:
here is a simple function (not at all optimized, and
only works with alpha images) to flip images
horizontally:
def flip_pixbuf(pb):
bps = pb.get_bits_per_sample()
rs = pb.get_rowstride()
pix = pb.get_pixels()
newpix = ""
x = rs
pixstride = pb.get_n_channels() * bps/8
while x <= len(pix):
row = pix[x - rs : x]
newrow = ""
x = x + rs
y = pixstride
while y <= len(row):
sample = row[y - pixstride :
y]
y = y + pixstride
newrow = sample + newrow
newpix = newpix + newrow
return gtk.gdk.pixbuf_new_from_data(newpix,
pb.get_colorspace(), \
pb.get_has_alpha(), bps,
pb.get_width(), \
pb.get_height(), rs)
If anyone can explain how to copy one pixbuf to
another, using a clip mask, I would be very pleased.
David
--- David Hugh-Jones <hughjonesd at yahoo.co.uk> wrote: >
> Hi All
>
> I have been using pygtk2 for some simple image
> manipulation. It's very nice, but I have two
> problems/questions that maybe someone can help with:
>
> 1. How can I flip a gtk.PixBuf image? I read an
> earlier message saying that this is "just a trivial
> manipulation of the buffer" - can someone tell me
> how
> a PixBuf buffer is structured?
>
> 2. I have a PixBuf created from a transparent PNG
> (with an alpha channel). When I do
>
> pixbuf.copy_area(background, ....)
>
> the pixbuf is copied on to background, but the
> transparency is rendered as a grey square. How can I
> make sure that the transparency gets rendered
> properly?
>
> Thanks very much for all replies.
>
> David Hugh-Jones
>
>
>
>
>
>
>
>
>
___________________________________________________________ALL-NEW
> Yahoo! Messenger - sooooo many all-new ways to
> express yourself http://uk.messenger.yahoo.com
> _______________________________________________
> pygtk mailing list pygtk at daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ:
> http://www.async.com.br/faq/pygtk/
>
___________________________________________________________ALL-NEW Yahoo! Messenger - sooooo many all-new ways to express yourself http://uk.messenger.yahoo.com
More information about the pygtk
mailing list