简体   繁体   English

如何使用drawinrect删除绘画中的空间?

[英]How to remove space in painting using drawinrect?

i'm using the following code to draw lines over an imageview's image, 我正在使用以下代码在imageview的图像上绘制线条,

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
if ([touch tapCount] == 2)
    return;
lastPoint = [touch locationInView:imageview];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    CGPoint currentPoint = [touch locationInView:self.view];
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), 3);
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5);
    UIGraphicsBeginImageContext(self.view.frame.size);
    [imageview.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    CGContextClearRect(UIGraphicsGetCurrentContext(), CGRectMake(lastPoint.x, lastPoint.y, 5, 5));
    imageview.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
lastPoint = currentPoint;
}

Output 输出量

在此处输入图片说明

You can see the gaps/spaces between the dots. 您可以看到点之间的间隙/空间。 I need the output should be like below, 我需要的输出应如下所示,

在此处输入图片说明

What should I change in my code to remove the space between two dots? 我应该在代码中进行哪些更改以删除两个点之间的空格?
I think, touchesended code is not needed for your review. 我认为, touchesended代码不需要您进行审核。 I changed the CGContextSetLineCap and width, no luck. 我改变了CGContextSetLineCap和宽度,没有运气。

I would change the approach, essentially you're capturing touch points, and not "joining the dots" so to speak. 我会改变方法,从本质上讲,您是在捕获接触点,而不是“连接点”。 You would be better off using UIBezierPaths for this task. 您最好将UIBezierPaths用于此任务。

I answered a question some time back where the op wanted to do something similar but was hitting performance issues. 不久前,我回答了一个问题,操作人员想做类似的事情,但遇到性能问题。 There is code in the answer i posted that pretty much does what you want, completely. 我发布的答案中有代码,几乎可以完全满足您的要求。 Review this post for full sample code, you can pretty much cut and paste the class (I see little value in transcribing). 查看这篇文章以获取完整的示例代码,您几乎可以剪切并粘贴该类(我认为转录的价值很小)。 Sample drawing path 样图路径

If you need more help just let me know 如果您需要更多帮助,请告诉我

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM