Re: Stumped on paint bucket in Core Image and polygons in Quartz
Re: Stumped on paint bucket in Core Image and polygons in Quartz
- Subject: Re: Stumped on paint bucket in Core Image and polygons in Quartz
- From: Scott Thompson <email@hidden>
- Date: Sun, 12 Jun 2005 20:15:15 -0700
In short, it treats the image as a resolution independent tiling
of color samples and generate the pixels from it (on pixel base
devices).
It seems to me (obviously wrong again) that this would make filling
an arbitrary area quite simple, and that there would by necessity
be some kind of support for polygons.
Well, there is support for polygons since you can represent a polygon
using a path. Paths. however, are not limited to containing just
straight line segments. They can also include curved segments.
To put it another way, every polygon is a path, but not every path is
a polygon.
Your seed fill, or flood fill, is a pixel level operation. It is
very device dependent. To make it work through Quartz, you are
going to want to take your drawing to a pixel device (like an
offscreen bitmap) and perform the flood fill in that environment.
Unfortunately, once you have done so, you're going to be limiting
the resolution of your image.
Youch. There's really no way to do this in Quartz?
There is a way to fill areas of a graphic (create a path that
outlines the area, then fill the path). There is not, however, a way
to ask the computer to fill the area surrounding a pixel because, as
I mentioned, a CGContext does not have any pixels.
This concept, that you are no longer drawing to the pixels, is a
very, very difficult concept for QuickDraw programmers to get used
to.
Actually, it's quite easy. What is hard to get used to is losing
features.
You haven't lost any features, you've completely changed drawing
models. What you've asked for is not a concept that fits into the
drawing model of Quartz.
Do you know of any example code showing how to do this? It looks
like I should use a path for this, correct?
Well... how about:
CGContextBeginPath(ctx);
CGContextMoveToPoint(ctx, 100, 100);
CGContextAddLineToPoint(ctx, 200, 100);
CGContextAddLineToPoint(ctx, 200, 200);
CGContextClosePath(ctx);
This snippet of code creates a path that is a triangle. Since the
path is composed of straight lines, it is also a three sided polygon.
To fill it, you would simply call CGContextFillPath(ctx);
Apart from that, there are plenty of sample codes. Some you might
find helpful are:
<http://developer.apple.com/samplecode/QuartzShapes/QuartzShapes.html>
<http://developer.apple.com/samplecode/Quartz_EB/Quartz_EB.html>
I might also humbly suggest:
<http://www.macdevcenter.com/pub/a/mac/2004/09/28/quartz.html>
and
<http://www.macdevcenter.com/pub/a/mac/2004/11/02/quartz.html>
The second of these articles creates a star-shaped path (a polygon)
Scott
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden