想要在 Quartz 的 ipad 绘画应用程序中添加手动擦除选项 [英] Want to add manual erasing option in ipad painting application by Quartz
本文介绍了想要在 Quartz 的 ipad 绘画应用程序中添加手动擦除选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 Quartz 2D for ipad 开发绘画应用程序.现在我想添加一个橡皮擦选项,以便用户可以通过触摸手动擦除他绘制的线条的一部分.我还有背景图像.有人可以帮忙吗?
I am working on a painting application using Quartz 2D for ipad. Now I want to add an eraser option so that user can manually erase portion of his drawn line with touch.I have also background image. Can anyone please help?
推荐答案
是的,这在我的应用中运行良好;-)
yes this is work well in my app ;-)
首先你在触摸开始添加这个代码
firstly you add this code in touch began
UITouch *touch = [touches anyObject];
lastPoint = [touch locationInView:imgview];
UIGraphicsBeginImageContext(imgview.frame.size);
[imgview.image drawInRect:CGRectMake(0, 0, imgview.frame.size.width, imgview.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), lineWidth);
CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(), [UIColor colorWithPatternImage:img].CGColor);
CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(), [UIColor clearColor].CGColor);
CGContextSetShouldAntialias(UIGraphicsGetCurrentContext(), YES);
CGContextBeginPath(UIGraphicsGetCurrentContext());
这里 img 是你的背景图片然后移动触摸你简单地写下代码就是这个的线条代码
here img is ur background image then on move touch you simple write the line stroke code that code is this
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:imgview];
NSLog(@"asdasdas");
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
imgview.image = UIGraphicsGetImageFromCurrentImageContext();
lastPoint = currentPoint;
然后你会看到最终的结果是产生;-)
then you see the final result is produce ;-)
这篇关于想要在 Quartz 的 ipad 绘画应用程序中添加手动擦除选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文