[cairo] how to cropping or clipping an image using cairo library
anurag swarnkar
anu_swar10 at yahoo.co.in
Sun Jan 27 23:01:07 PST 2008
Thanks a lot Carl. That piece of code was very informative.
----- Original Message ----
From: Carl Worth <cworth at cworth.org>
To: anurag swarnkar <anu_swar10 at yahoo.co.in>
Cc: cairo at cairographics.org
Sent: Monday, 28 January, 2008 8:02:23 AM
Subject: Re: [cairo] how to cropping or clipping an image using cairo library
On Mon, 28 Jan 2008 10:58:21 +0530 (IST), anurag swarnkar wrote:
> I want to know whether there is any API available in cairo through
> which i can crop or clip (getting a portion of image) an image?
Yes.
The simplest case, (which I'm guess is what you're wanting), is just a
rectangle, but doing fancier stuff isn't actually any harder. I'll
show both.
For example, if you have the image in a cairo surface named "image"
and you are drawing to some cairo context "cr" then you might do
something like this, (let's assume that we want the origin of the
complete image at (x0,y0) and that we want to display only a
rectangular portion of the image (x,y)-(width,height)). So that would
look like:
cairo_set_source_surface (cr, image, x0, y0);
cairo_rectangle (cr, x0 + x, y0 + y, width, height);
cairo_fill (cr);
And if you wanted to crop out a circular portion of the image, you
might instead do:
cairo_set_source_surface (cr, image, x0, y0);
cairo_arc (cr, x0 + width / 2, y0 + height / 2,
MIN (WIDTH,HEIGHT) / 2, 0, 2 * M_PI);
cairo_fill (cr);
Or if you wanted to crop out any polygonal region in points (a,b),
(c,d)...:
cairo_set_source_surface (cr, image, x0, y0);
cairo_move_to (cr, a, b);
cairo_line_to (cr, c, d);
...
cairo_fill (cr);
Anyway, hopefully that gives you the basic idea. And of course, you
can "crop out" text-shaped portions of an image with
cairo_set_source_surface;cairo_show_text as well.
Have fun with cairo!
-Carl
Why delete messages? Unlimited storage is just a click away. Go to http://help.yahoo.com/l/in/yahoo/mail/yahoomail/tools/tools-08.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.cairographics.org/archives/cairo/attachments/20080128/98dfaf5c/attachment.htm
More information about the cairo
mailing list