[cairo] Forcing black and white or grayscale

Lawrence D'Oliveiro ldo at geek-central.gen.nz
Fri Apr 22 23:13:37 UTC 2016


On Fri, 22 Apr 2016 18:26:21 +0000 (UTC), Michele Cleary wrote:

> Does anyoneknow how to use cairo to force a job to be black and white
> or grayscale?

It’s quite simple:

1) Draw the full-colour image into the destination image surface
2) Set a source colour RGB = (255, 255, 255) and transfer mode
CAIRO_OPERATOR_HSL_COLOR <http://cairographics.org/operators/#hsl_color>
3) Paint this source all over the destination image surface. That will
replace the hue and saturation (in particular, set the saturation to
zero), leaving the greyscale intensities unchanged.


More information about the cairo mailing list