user2675697
user2675697

Reputation: 1

objective-c fill up color in specific area and only when touched

I have tried and searched a lot but have not find a solutions.

I have f.e this picture as a .png [1]: http://imm.io/1f3DY

If the user touches f.e. in the area 1

I want to fill up this area with color f.e. blue.

Is there any way to find out/create these areas in code and fill it up with colors?

I have convert my .png to .svg and created some bezierpathes. Stored the bezierpathes in an array and add a gesturerecognizer. This works fine. Got the right path which I have touched. Can change the color of the path. But only the black lines. I want to fill up the space between f.e. path1 and path 2. How can I do this?

       //The event handling method
- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer {
    CGPoint location = [recognizer locationInView:[recognizer.view superview]];

    location.y = self.view.bounds.size.height - location.y;
    for(int i = 0; i< bezierPathes.count; i++)
    {
          //if([b containsPoint:location])

        UIBezierPath* b = bezierPathes[i];
        if([[self tapTargetForPath:b] containsPoint:location])
        {
            [[UIColor redColor] setFill];
            [b fill];
            [testView setNeedsDisplay];

        }

    }
}

// this method will let you easily select a bezier path ( 15 px up and down of a path drawing)
- (UIBezierPath *)tapTargetForPath:(UIBezierPath *)path
{
    if (path == nil) {
        return nil;
    }

    CGPathRef tapTargetPath = CGPathCreateCopyByStrokingPath(path.CGPath, NULL, fmaxf(35.0f, path.lineWidth), path.lineCapStyle, path.lineJoinStyle, path.miterLimit);
    if (tapTargetPath == NULL) {
        return nil;
    }

    UIBezierPath *tapTarget = [UIBezierPath bezierPathWithCGPath:tapTargetPath];
    CGPathRelease(tapTargetPath);
    return tapTarget;
}

Upvotes: 0

Views: 844

Answers (1)

virantporwal
virantporwal

Reputation: 987

You can also do this with Flood Fill algorithm.

Hear is the link http://en.wikipedia.org/wiki/Flood_fill

Upvotes: 1

Related Questions