Re: setting a transparent color on a pixbuf for Canvas layering




On Jun 30, 2008, at 5:52 PM, zentara wrote:

How do I take the non-transparent zzrgbwb.png , load it with Gtk2, and
make green transparent without resorting to GD?


Short answer:  Just use GD.  There's no shame in it.


Long answer: It sounds like what you really want is to create an alpha mask from certain areas of your source image. The basic algorithm is:

1.  blow your 24-bit rgb data up to 32-bit rgba with a all set to 255
2. walk through each pixel in the image, setting the alpha channel for that pixel where the rgb values match some criteria.
3.  done.

This is easily done with GdkPixbuf in C; you just get a pointer to the pixel data and go to town with a trivial loop.

In perl, it's a bit more difficult to manage a GdkPixbuf's image data. You could write some XS to do it in C with speed and ease, but then you have XS code to deal with. You could write it in perl and deal with a map-reduce and unpack and pack and all the fun stuff there, and hope you can get the speed reasonable.

Or, just use GD, which has already solved the problem for you.



--
The one difference between Dali and a crazy man is very simple: Dali is not crazy at all.
  -- Salvador Dali





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]