[cairo] render in grayscale

Per Hermansson hermansson.per at bredband.net
Tue Sep 22 11:01:25 PDT 2009


Behdad Esfahbod wrote:
> On 09/22/2009 01:00 PM, Bill Spitzak wrote:
>> I think the original poster wants to render not the alpha, but something
>> like (r+g+b)/3 of the image as grayscale.
>
> That's exactly what the solution Kalle and I proposed does.  Though, 
> one typically wants a non-uniform combination of rgb for grayscale, 
> with green getting a larger multiplier.
>
> behdad

So if I understand correctly rendering with the alpha surface as mask 
should  work to get all colors replaced with different gray values?
After I applied the suggested changes, with the following code:
  cairo_set_source_rgb(cr, 0, 0, 0);
  pattern = cairo_pattern_create_for_surface(target);
  cairo_mask(cr, pattern);

I only get a white background with a filled black rectangle, how is the 
transparency supposed to work?

Per


More information about the cairo mailing list