iOS着色透明图像

时间:2012-04-14 07:22:45

标签: ios xcode

我正在尝试开发一个着色应用程序。我想从空白画布开始,并且当用户使用触摸颜色时,我想仅显示彩色图像的那些触摸区域。我该如何实现这一目标?任何帮助对我都有很大的帮助。

1 个答案:

答案 0 :(得分:0)

可能这将有助于您启动

UITouch *touch = [touches anyObject];   

    CGPoint currentPoint = [touch locationInView:drawImage];


    UIGraphicsBeginImageContext(drawImage.frame.size);

    [drawImage.image drawInRect:CGRectMake(0, 0, drawImage.frame.size.width, drawImage.frame.size.height)];

    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);

    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), size);


      CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), r, g, b, a);


    CGContextBeginPath(UIGraphicsGetCurrentContext());

    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);

    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);

    CGContextStrokePath(UIGraphicsGetCurrentContext());

    drawImage.image = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

虽然我没有尝试过,但在SO问题上发现它可以正常工作