[cairo] Get pixel colour

Behdad Esfahbod behdad at behdad.org
Sun Jul 29 17:03:50 PDT 2007

On Sun, 2007-07-29 at 12:41 -0400, Sikamikaniboots wrote:
> Hi !
> In my app, I use gtk printing. All the drawing are done on a cairo
> context.
> I need to access the rgba data from a given pixel.
> Do you now any way to do that ?

Hi and welcome to the cairo list,

If you are printing to a printer, or PDF file,  what is a pixel anyway?
Cairo is not a pixel-based model.  There are backend-specific ways to do
what you want, with the pixel-based backends, but no general way.

For the image surface, you can use cairo_image_surface_get_data(),
get_format(), get_width(), get_height(), and get_stride() to find the
rgba data of any pixel you want yourself.

The right question may be, why do you need such a thing?

> I've read the doc but couldn't find it...
> Thanks !

Have fun with cairo!

"Those who would give up Essential Liberty to purchase a little
 Temporary Safety, deserve neither Liberty nor Safety."
        -- Benjamin Franklin, 1759

More information about the cairo mailing list