在iOS中为paint应用程序制作橡皮擦工具

在iOS中为paint应用程序制作橡皮擦工具,第1张

概述我正在创建一个绘图应用程序,我想知道如何实现橡皮擦工具.我不想让我的橡皮擦工具绘制白色,因为我想让用户更改背景颜色.而且,是否可以设定刷子的硬度?如果是,请告诉我如何. 谢谢 这是我到目前为止所做的: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ UITouch *touch = [touches an 我正在创建一个绘图应用程序,我想知道如何实现橡皮擦工具.我不想让我的橡皮擦工具绘制白色,因为我想让用户更改背景颜色.而且,是否可以设定刷子的硬度?如果是,请告诉我如何.

谢谢

这是我到目前为止所做的:

- (voID)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{    UItouch *touch = [touches anyObject];    lastPoint = [touch locationInVIEw:self.vIEw];}- (voID)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{    UItouch *touch = [touches anyObject];    CGPoint currentPoint = [touch locationInVIEw:self.vIEw];    UIGraphicsBeginImageContext(self.vIEw.frame.size);    [drawImage.image drawInRect:CGRectMake(0,self.vIEw.frame.size.wIDth,self.vIEw.frame.size.height)];    CGContextSetlineCap(UIGraphicsGetCurrentContext(),kCGlineCapRound);    CGContextSetlinewidth(UIGraphicsGetCurrentContext(),10);    CGContextBeginPath(UIGraphicsGetCurrentContext());    CGContextSetRGBstrokecolor(UIGraphicsGetCurrentContext(),0.0,1.0);    CGContextMovetoPoint(UIGraphicsGetCurrentContext(),lastPoint.x,lastPoint.y);    CGContextAddlinetoPoint(UIGraphicsGetCurrentContext(),currentPoint.x,currentPoint.y);    CGContextstrokePath(UIGraphicsGetCurrentContext());    drawImage.image = UIGraphicsGetimageFromCurrentimageContext();    UIGraphicsEndImageContext();    lastPoint = currentPoint;}- (voID)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{UItouch *touch = [touches anyObject];CGPoint currentPoint = [touch locationInVIEw:self.vIEw];UIGraphicsBeginImageContext(self.vIEw.frame.size);[drawImage.image drawInRect:CGRectMake(0,self.vIEw.frame.size.height)];CGContextSetlineCap(UIGraphicsGetCurrentContext(),kCGlineCapRound);CGContextSetlinewidth(UIGraphicsGetCurrentContext(),10);CGContextBeginPath(UIGraphicsGetCurrentContext());CGContextSetRGBstrokecolor(UIGraphicsGetCurrentContext(),1.0);CGContextMovetoPoint(UIGraphicsGetCurrentContext(),lastPoint.y);CGContextAddlinetoPoint(UIGraphicsGetCurrentContext(),currentPoint.y);CGContextstrokePath(UIGraphicsGetCurrentContext());drawImage.image = UIGraphicsGetimageFromCurrentimageContext();UIGraphicsEndImageContext();lastPoint = currentPoint;}- (IBAction)clear:(ID)sender {drawImage.image = nil;}
解决方法 好的,这就是我为橡皮擦工具所做的:
我添加这行代码:
CGContextSetBlendMode(UIGraphicsGetCurrentContext(),kCGBlendModeClear);

所以代码将是这样的东西:

- (voID)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{UItouch *touch = [touches anyObject];CGPoint currentPoint = [touch locationInVIEw:self.vIEw];UIGraphicsBeginImageContext(self.vIEw.frame.size);[drawImage.image drawInRect:CGRectMake(0,self.vIEw.frame.size.height)];// I add thisCGContextSetBlendMode(UIGraphicsGetCurrentContext(),kCGBlendModeClear);CGContextSetlineCap(UIGraphicsGetCurrentContext(),sizeSlIDer.value);CGContextBeginPath(UIGraphicsGetCurrentContext());CGContextSetBlendMode(UIGraphicsGetCurrentContext(),kCGBlendModeClear);CGContextMovetoPoint(UIGraphicsGetCurrentContext(),currentPoint.y);CGContextstrokePath(UIGraphicsGetCurrentContext());drawImage.image = UIGraphicsGetimageFromCurrentimageContext();UIGraphicsEndImageContext();lastPoint = currentPoint;}
总结

以上是内存溢出为你收集整理的在iOS中为paint应用程序制作橡皮擦工具全部内容,希望文章能够帮你解决在iOS中为paint应用程序制作橡皮擦工具所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1102598.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存