2

我正在使用 CoreGraphics 在背景图像上实现自由手绘,这对我来说工作正常,现在我想为此绘图实现擦除功能,以便用户可以清除他的绘图

4

2 回答 2

0

如果您只想清除屏幕,请删除您创建的 CGPath,它不会绘制任何内容。

如果你想让使用切换到橡皮擦工具并且只擦除某些东西,你需要设置一个新的绘图类,让你在其他绘图上绘制背景或调整你必须不绘制交叉点的类在原始路径和橡皮擦路径之间。

于 2013-01-16T13:36:04.210 回答
0

您可以在 UITouch 方法“touchesMoved”中使用它来清除您绘制的路径

`UITouch *touch = [[event allTouches] anyObject];

currenttouch = [触摸 locationInView:drawingImageView];

CGColorRef strokeColor = [UIColor blackColor].CGColor;

UIGraphicsBeginImageContext(drawingImageView.frame.size);

    CGContextRef context = UIGraphicsGetCurrentContext();


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

    CGContextSetLineCap(context, kCGLineCapRound);

    CGContextSetLineWidth(context, brushSize);

    CGContextSetStrokeColorWithColor(context, strokeColor);

    CGContextSetBlendMode(context, kCGBlendModeClear);

    CGContextBeginPath(context);

    CGContextMoveToPoint(context, currenttouch.x, currenttouch.y);

    CGContextAddLineToPoint(context, currenttouch.x, currenttouch.y);

    CGContextStrokePath(context);

    drawingImageView.image = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

`

于 2013-01-16T13:52:51.223 回答