CGContextClearRect在touchesMove事件中无法在目标C中顺利运行

吉山·戈达尼(kishan godhani)

我使用了这段代码,但部分起作用,但是图像无法正确裁剪,如下所示

-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:_img.superview];

UIGraphicsBeginImageContext(self.img.frame.size);
[_img.image drawInRect:CGRectMake(0, 0, _img.frame.size.width, _img.frame.size.height)];

CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 10);
CGContextBeginPath(UIGraphicsGetCurrentContext());

CGContextClearRect (UIGraphicsGetCurrentContext(), CGRectMake(currentPoint.x, currentPoint.y, 15, 15));
CGContextStrokePath(UIGraphicsGetCurrentContext());
_img.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();   
}
维拉吉·帕萨拉(Viraj Padsala)

我之前遇到过同样的问题,然后尝试了以下代码,这对我来说很有效

UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:self.img_main];
// NSLog(@"Current ponint : %f,%f",currentPoint.x,currentPoint.y);

self.img_main.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
self.img_main.contentMode = UIViewContentModeScaleAspectFit;

UIGraphicsBeginImageContextWithOptions(self.img_main.bounds.size, NO, 0.0);
[_img_main.image drawInRect:CGRectMake(0,0, self.img_main.bounds.size.width,self.img_main.bounds.size.height)];
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);

//For clearing Size and Mode
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), brush_Size );
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeDestinationOut);
//For Clearing Opacity        
CGContextSetAlpha(UIGraphicsGetCurrentContext(), brush_opacity);
CGContextStrokePath(UIGraphicsGetCurrentContext());

_img_main.image = UIGraphicsGetImageFromCurrentImageContext();

CGContextFlush(UIGraphicsGetCurrentContext());
UIGraphicsEndImageContext();

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

CGContextClearRect在touchesMove事件中无法在目标C中顺利运行

来自分类Dev

-(BOOL)webview:无法在目标c xcode中运行

来自分类Dev

无法在Django URL中顺利导航

来自分类Dev

程序在多线程中无法顺利结束

来自分类Dev

无法从NetBeans 8.0.2中运行的ant目标运行psql

来自分类Dev

在javascript中顺利滚动?

来自分类Dev

无法顺利滚动android 4.1中的图像的listView

来自分类Dev

viewpager中2页之间的过渡无法顺利进行

来自分类Dev

如何在目标C中创建事件循环?

来自分类Dev

为什么下拉事件无法在ASP中运行

来自分类Dev

Bootstrap幻灯片事件无法在AJAX中成功运行

来自分类Dev

无法获得在Sterling Trader样本中运行的事件

来自分类Dev

我在CSS中遇到问题,无法在菜单栏中顺利移动?

来自分类Dev

目标C-无法更改NSMutableArray中的值

来自分类Dev

CGContextClearRect忽略情节提要中设置的Alpha值

来自分类Dev

无法在eclipse中作为c ++项目运行

来自分类Dev

C ++中的char数组无法正常运行

来自分类Dev

无法在Shell中调用的Makefile中的目标

来自分类Dev

稍后在C ++中安排事件:如何传递要运行的任务

来自分类Dev

在.NET / C#中完成事件后运行操作

来自分类Dev

在Typescript中运行BackboneJs事件

来自分类Dev

在Typescript中运行BackboneJs事件

来自分类Dev

数据切换和数据目标无法在引导程序中运行

来自分类Dev

当目标字符串包含在列表中时,str.replace似乎无法正常运行

来自分类Dev

当目标字符串包含在列表中时,str.replace似乎无法正常运行

来自分类Dev

无法在 iOS Swift 3 中的 UIBarButtonItem 单击上添加目标和运行功能

来自分类Dev

如何在Xcode中运行首选目标?

来自分类Dev

在配置文件中运行插件目标

来自分类Dev

在Gradle任务中运行Ant目标

Related 相关文章

  1. 1

    CGContextClearRect在touchesMove事件中无法在目标C中顺利运行

  2. 2

    -(BOOL)webview:无法在目标c xcode中运行

  3. 3

    无法在Django URL中顺利导航

  4. 4

    程序在多线程中无法顺利结束

  5. 5

    无法从NetBeans 8.0.2中运行的ant目标运行psql

  6. 6

    在javascript中顺利滚动?

  7. 7

    无法顺利滚动android 4.1中的图像的listView

  8. 8

    viewpager中2页之间的过渡无法顺利进行

  9. 9

    如何在目标C中创建事件循环?

  10. 10

    为什么下拉事件无法在ASP中运行

  11. 11

    Bootstrap幻灯片事件无法在AJAX中成功运行

  12. 12

    无法获得在Sterling Trader样本中运行的事件

  13. 13

    我在CSS中遇到问题,无法在菜单栏中顺利移动?

  14. 14

    目标C-无法更改NSMutableArray中的值

  15. 15

    CGContextClearRect忽略情节提要中设置的Alpha值

  16. 16

    无法在eclipse中作为c ++项目运行

  17. 17

    C ++中的char数组无法正常运行

  18. 18

    无法在Shell中调用的Makefile中的目标

  19. 19

    稍后在C ++中安排事件:如何传递要运行的任务

  20. 20

    在.NET / C#中完成事件后运行操作

  21. 21

    在Typescript中运行BackboneJs事件

  22. 22

    在Typescript中运行BackboneJs事件

  23. 23

    数据切换和数据目标无法在引导程序中运行

  24. 24

    当目标字符串包含在列表中时,str.replace似乎无法正常运行

  25. 25

    当目标字符串包含在列表中时,str.replace似乎无法正常运行

  26. 26

    无法在 iOS Swift 3 中的 UIBarButtonItem 单击上添加目标和运行功能

  27. 27

    如何在Xcode中运行首选目标?

  28. 28

    在配置文件中运行插件目标

  29. 29

    在Gradle任务中运行Ant目标

热门标签

归档