突出显示图像的一部分

时间:2014-06-12 15:07:35

标签: ios objective-c image-processing uiimageview uiimage

我正在尝试实现一个功能,您可以突出显示部分图像并裁剪它。我见过一款名为“My Cam”的应用程序,它有一些很棒的高亮机制,我认为它可能会使用颜色检测,看看我是如何能够轻松突出显示器的银色部分的:

enter image description here

我是Quartz2D的新手所以请原谅我的无知,我能够在Image上实现基本的突出显示,这是一个代码示例:

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint currentPoint = [touch locationInView:_frontView];
    UIGraphicsBeginImageContext(_frontView.frame.size);
    [_frontView.image drawInRect:CGRectMake(0, 0, _frontView.frame.size.width, _frontView.frame.size.height)];
    CGContextSaveGState(UIGraphicsGetCurrentContext());
    //CGContextSetShouldAntialias(UIGraphicsGetCurrentContext(), YES);
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 25.0);
    //CGContextSetShadowWithColor(UIGraphicsGetCurrentContext(), CGSizeMake(0, 0), 50, [[UIColor whiteColor]CGColor]);

    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path, nil, lastPoint.x, lastPoint.y);
    CGPathAddLineToPoint(path, nil, currentPoint.x, currentPoint.y);
        CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(), [[UIColor colorWithRed:109/255.0f green:110/255.0f blue:112/255.0f alpha:0.5f] CGColor]);
    CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeOverlay);

    CGContextAddPath(UIGraphicsGetCurrentContext(), path);
    CGContextStrokePath(UIGraphicsGetCurrentContext());
    _frontView.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    CGPathMoveToPoint(lastPath, nil, lastPoint.x, lastPoint.y);
    CGPathAddLineToPoint(lastPath, nil, currentPoint.x, currentPoint.y);

    lastPoint = currentPoint;
}

任何提示都会受到赞赏,我认为在图像中做一些像初学者需要几个月的工作。我希望在github上找到一些东西,但我的搜索失败了。

0 个答案:

没有答案