[cairo] CAIRO_FORMAT_A1 image source color

sthustfo sthustfo at gmail.com
Fri Mar 28 09:51:43 PDT 2014


Hi Uli,

Thanks for the clarification regarding the A1 and A8 formats. I did not
notice this in the documentation. Further, when I run the sample program
provided by you, the generated out.png is 1x2 image in complete black. I do
not see the white pixel.

I would like to generate a white surface and then draw some text over it in
black using pango layout api (pango_layout_set_text). And then make use the
raw data of the surface, and not really interested in the png output. Is
this possible using the cairo?

Thanks in advance.


On Fri, Mar 28, 2014 at 6:15 PM, Uli Schlachter <psychon at znc.in> wrote:

> Hi,
>
> 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
> > background.
> >
> > 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.
>
> Cheers,
> Uli
> --
> No matter how much cats fight, there always seem to be plenty of kittens.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20140328/5c0602fc/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: out.png
Type: image/png
Size: 83 bytes
Desc: not available
URL: <http://lists.cairographics.org/archives/cairo/attachments/20140328/5c0602fc/attachment.png>


More information about the cairo mailing list