如何对 Quartz2d 绘图中的某个点执行擦除功能?
我使用这段代码在quartz2d 中画一条线
CGPoint currentPoint = CGPointMake(rascalImage.center.x, rascalImage.center.y);
currentPoint.y += 10;
UIGraphicsBeginImageContext(self.view.frame.size);
[drawingView.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
drawingView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
lastPoint = currentPoint;
现在我该如何为橡皮擦相交的地方创建一个擦除函数呢?我知道我必须从线上擦除某个点(橡皮擦接触的地方),我只是不知道该怎么做,所以请帮忙!
I use this code to draw a line in quartz2d
CGPoint currentPoint = CGPointMake(rascalImage.center.x, rascalImage.center.y);
currentPoint.y += 10;
UIGraphicsBeginImageContext(self.view.frame.size);
[drawingView.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
drawingView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
lastPoint = currentPoint;
Now how would I go about making an erase function for just where the eraser intersects? I know that I have to erase a certain point from the line (where the eraser touches), I just don't know how to do this so please help!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我猜你不是在纯色背景上画画的?如果是,只需使用相同的函数在对比线上绘制背景色线即可。
但是,由于您很可能有一个复杂的背景:一旦结束图形上下文并从您绘制的线条中获取 UIImage,就无法仅删除线条。如果您正在创建某种复杂的绘图应用程序,我建议您使用图层,并简单地将图层“堆叠”在另一个图层之上以创建绘图环境。
另请查看这篇文章:
如何在 iOS 上删除 UIImageView 图像的某些部分?
I assume you are not drawing on a solid colored background? If you are, just use the same function to draw background-colored lines over the contrasting lines.
But, since you most likely have a complex background: Once you end the graphics context, and get a UIImage from the lines you have drawn, there is no way to erase just the lines. If you are creating some sort of complex drawing app, I would suggest that you use layers, and simply "stack up" layers one on top of the other to create the drawing environment.
Check out this post also:
How to erase some portion of a UIImageView's image on iOS?