Does somebody know about a flood fill function for Cocoa ?
29/11/03 10:16
I need to implement an efficient flood fill for NSImage...
Here is an example of an implementation. To use in your application, extract the framework from the example and add it to your project. For source code send a mail here.
It contains two methods extending the NSBitmapImageRep class. Both returns YES if the bitmap format is recognized by the routine. Supported formats are the meshed ones: 8 bits grayscale, 16-bits rgb, 24 bits rgb and 32 bits rgba. The optional "tolerance" parameter has to be in the [0.0 ; 1.0] range. 0.05 will mean a 5% tolerance. Algorithm used is the classic non-recursive scan line one with reduced stack requirements.
@interface NSBitmapImageRep(Floodfill)
- (BOOL)floodFillFrom:(NSPoint)inStartPoint withColor:(NSColor *)inColor;
- (BOOL)floodFillFrom:(NSPoint)inStartPoint withColor:(NSColor *)inColor andTolerance:(float)inTolerance;
@end
It contains two methods extending the NSBitmapImageRep class. Both returns YES if the bitmap format is recognized by the routine. Supported formats are the meshed ones: 8 bits grayscale, 16-bits rgb, 24 bits rgb and 32 bits rgba. The optional "tolerance" parameter has to be in the [0.0 ; 1.0] range. 0.05 will mean a 5% tolerance. Algorithm used is the classic non-recursive scan line one with reduced stack requirements.
@interface NSBitmapImageRep(Floodfill)
- (BOOL)floodFillFrom:(NSPoint)inStartPoint withColor:(NSColor *)inColor;
- (BOOL)floodFillFrom:(NSPoint)inStartPoint withColor:(NSColor *)inColor andTolerance:(float)inTolerance;
@end