[cairo] Draw a single pixel or group of pixels

Carl Worth cworth at cworth.org
Thu Apr 10 10:27:30 PDT 2008


On Thu, 10 Apr 2008 13:10:36 -0400, "Joseph Fradley" wrote:
> On Thu, Apr 10, 2008 at 12:28 PM, Dirk Schönberger <dirk.schoenberger at sz-online.de> wrote:
> > I am afraid that the concept of a pixel is not longer available in a Cairo
> > style API.
> > All you can do is to create one or multiple rectangular path elements and
> > hope hat they match to single pixels after rendering them to your output
> > device.
>
> Well that's a bummer. I'm going to need precise graphics for use with image
> analysis software. So, I'm probably going to switch to SDL_gfx, unless you
> have other suggestions? Thanks for your help.

I think you may have misunderstood Dirk here slightly.

It's true that cairo doesn't provide any "set pixel" API, but it does
provide very accurate and reliable drawing operations.

So you definitely can get precise, pixel-aligned results as much as
you'd like, (excepting bugs of course). The word "hope" in Dirk's
answer is perhaps overstating the case a bit. You can definitely
"trust" that careful input will hit pixel boundaries, (assuming you
are targeting a pixel-oriented device rather than something like
PostScript or PDF output).

As mentioned in a previous response, an easy way to "light up" a
single pixel is with:

	cairo_rectangle (cr, x, y, 1, 1);
	cairo_set_source_rgb (cr, red, green, blue);
	cairo_fill (cr);

(This is assuming an identity transformation, which is the default.)

You can also do multiple rectangles and a single fill if you'd
like. And you could also put data directly into an RGB buffer and then
do cairo_image_surface_create_for_data.

So there are multiple ways to achieve the result you want. Which way
is preferable will depend on further details of exactly what you're
trying to do.

Please let us know if we can be of any further help,

And have fun with cairo!

-Carl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.cairographics.org/archives/cairo/attachments/20080410/15f6e5b9/attachment.pgp 


More information about the cairo mailing list