[cairo] Displaying images

Carl Worth cworth at cworth.org
Fri Mar 4 04:41:12 PST 2005


On Fri, 4 Mar 2005 16:59:14 +1100, "Matthew Allen" wrote:
> I mean how do you paste a in memory bitmap on to the working surface...?
> 
> So far I assume that you use cairo_surface_create_for_image to
> create a surface around the source image. And then...?

And then (with the current API) you also need to create a pattern from
that surface (cairo_pattern_create_for_surface), then set that as the
current pattern (cairo_set_pattern). And then when you next draw
something it will get its color from the pattern (your image). So you
might likely draw a rectangle (cairo_rectangle, then cairo_fill).

That's a lot of work so the current API provides a single call to do
it all for you:

	cairo_show_surface

which also leaves the current pattern unmodified by the time it
returns.

> With Gdi+ I could blat the bitmap anywhere on the document and it
> would be transformed using the current matrix to rotate and scale or
> whatever. Can cairo do that yet?

Yes, the calls described above do all that. There's a cairo snippet
that demonstrates cairo_show_surface, (both in code and with the
graphics result), here:

	http://cairographics.org/samples/image.html

I hope that helps.

-Carl

PS. With the future API things are similar, but the cairo_set_pattern
is renamed to cairo_set_source, (which seems more natural given the
phrasing of your question). We'll also provide cairo_set_source_surface 
so you won't have to also create the intermediate pattern object.

Also, the new API will remove cairo_show_surface, but will provide a
more general function, cairo_paint, which should be almost as easy to
use, but will have much cleaner semantics, (cairo_set_source_surface/
cairo_paint as opposed to cairo_show_surface).

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20050304/048eb87e/attachment.pgp


More information about the cairo mailing list