Re: How to get the image mask path
Re: How to get the image mask path
- Subject: Re: How to get the image mask path
- From: Uli Kusterer <email@hidden>
- Date: Fri, 21 Jul 2006 13:32:55 +0200
Am 21.07.2006 um 11:06 schrieb Vinay Prabhu:
If the image has only one masked area, is it possible to get the path?
I don't know how to achieve this on Mac,
but on windows it is possible.
Please have a look at the attached image.
Well, one very simplistic approach you could take would be to first
detect the outline of the image, e.g. by going over each of the rows
of the image and recording it as ranges of starting and ending
coordinates. A starting coordinate is where a transparent (or white,
or whatever your background is) pixel is followed by an opaque pixel.
Ending coordinate would be where an opaque pixel is followed by a
transparent one. You'd do that for horizontal pixels (i.e. "inside
the row") as for vertical pixels ("between" the rows).
You'd have a very crude polygon-ish approximation of your image.
Now you'd have to somehow group together adjacent pixels into shapes,
so you have the "holes" and the outline as separate shapes. Finally,
you'd take three pixels each following the other and see whether you
can smooth them by e.g. turning them into two pixels with a curve
between them that goes through the third, or if they're exactly on
one line, or if they express a right angle, you'd turn them into line
segments instead.
That should smooth out the curves a little. Once you have all these
coordinates collected, building an NSBezierPath from them should be
trivial.
But as I said, that would be a very simplistic and crude approach,
and I'm not sure it's easy to to actually detect the shapes of
adjacent pixels.
Cheers,
-- M. Uli Kusterer
http://www.zathras.de
_______________________________________________
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