Re: hit detection with NSBezierPath... And more....
Re: hit detection with NSBezierPath... And more....
- Subject: Re: hit detection with NSBezierPath... And more....
- From: Marco Binder <email@hidden>
- Date: Sat, 03 Aug 2002 15:08:04 +0200
I recently asked a question in here about how to get access to all the
pixels contained by an NSBezierPath. Since nobody answered (besides the one
answer pointing out that NSBezierPaths do not have pixels), I thought a
while and came up with a virtually identical solution as the one you just
described. Maybe someone wants to know:
If you have a view having an image as background and an NSBezierPath ontop
and you now want to know things like the area enclosed by the path or the
pixel-values of the image beneath the path, the way to go is also to utilize
an offscreen view. Just create an new NSImage, set the clipping path to your
NSBezierPath and draw your background image into this new image (for
performance reasons, better use only the rect defined by yourPath:bounds).
You can get the bitmap data of the offscreen image and just count the
non-transparent pixels (alpha channel == 0) to get the area. Or, of course,
get the RGB-values for the pixels whose alpha != 0.
I, too, can just emphasize the importance to turn off antialiasing for the
offscreen image since otherwise you wont get crisp edges (alpha-values
between 0 and 255).
It might seems pretty slow, but it s not. Even my amateur class written in
Java allows for smooth dragging of the path while area and RGB-values are
still calculated in real-time.
marco
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.