[cairo] CAIRO_FORMAT_A1 image source color
psychon at znc.in
Fri Mar 28 05:45:23 PDT 2014
On 28.03.2014 07:01, sthustfo wrote:
> I am using cairopango library to render text on monochrome image on Ubuntu
> 13.10. Now before rendering text, I create a surface of type
> CAIRO_FORMAT_A1, create a cairo context and set the source to solid white.
> However, the color of the image remains black even though I have set the
> color source to solid white. I want to render black color text on white
> surface = cairo_image_surface_create (CAIRO_FORMAT_A1, 320, 280);
> cr = cairo_create (surface);
> cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 1.0);
> cairo_paint (cr);
> cairo_surface_write_to_png (surface, filename);
> The saved PNG image always is black color. How do I achieve an image of
> solid white color for a monochrome image (CAIRO_FORMAT_A1)? If suppose, the
> surface is created using CAIRO_FORMAT_ARGB32, then everyrhing is fine.
Please note that CAIRO_FORMAT_A1 and CAIRO_FORMAT_A8 are *not* monochrome
images. They describe images without any colors at all which only contain an
alpha channel. Only when generating a PNG are these images interpreted as
monochrome. The contents of the color components in your call to
cairo_set_source_rgba() won't make any difference at all.
Also note that the default operator (CAIRO_OPERATOR_OVER) doesn't allow to
"remove transparency", it only ever is added.
Attached is a program which generates a PNG with a white and a black pixel. It
uses the operator "SOURCE" to set the alpha-value of the target pixel. I hope
this can help you.
No matter how much cats fight, there always seem to be plenty of kittens.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 506 bytes
Desc: not available
More information about the cairo