[英]How to delete a drawn CGPoint on a UIImageView
I have a UIImageView
that i draw on it points . 我有一个UIImageView
,我在上面画了点。 I store my CGpoint
in an NSArray
with a capacity of 100. Every time i receive a new CGpoint i want to erase the last object from the array , remove it from the array and then draw the new CGpoint
and add it to the array. 我将CGpoint
存储在容量为100的NSArray
中。每次接收到新的CGpoint时,我都希望从阵列中删除最后一个对象,将其从阵列中删除,然后绘制新的CGpoint
并将其添加到阵列中。
So how do i erase a CGpoint
? 那么我该如何清除CGpoint
? and have only 100 CGpoint
on my UIImageView
? 而且我的UIImageView
上只有100 CGpoint
吗?
My code: 我的代码:
- (void) drawLine:(CGPoint)pt onCanvas:(UIImageView *)canvas color:(UIColor *)color
{
UIGraphicsBeginImageContext(canvas.frame.size);
[canvas.image drawInRect:CGRectMake(0, 0, canvas.frame.size.width, canvas.frame.size.height)];
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetLineCap(ctx, kCGLineCapButt);
CGContextSetLineWidth(ctx,10.0);
CGContextSetRGBStrokeColor(ctx, 1.0, 0.0, 0.0, 1.0);
CGContextBeginPath(ctx);
CGContextAddEllipseInRect (ctx,CGRectMake(pt.x-2.0, pt.y-2.0, 4, 4));
CGContextSetFillColorWithColor(ctx,color.CGColor);
CGContextFillPath(ctx);
CGContextStrokePath(ctx);
canvas.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
You cannot remove points from an image. 您无法从图像中删除点。 It's an image - imagine it like a photo you have taken and then you try to remove the background from it. 这是一幅图像-想象它就像您拍摄的照片,然后尝试从中删除背景。 It's impossible. 不可能。
The best thing you can do is not to use a double buffer - just keep the points in your array and paint them all when needed. 您可以做的最好的事情就是不要使用双缓冲区-只需将点保留在数组中,并在需要时绘制所有点即可。 Then you won't have to remove anything. 然后,您将不必删除任何内容。 It's true this could affect the performance a bit but 100 points should still be fine. 的确,这可能会稍微影响性能,但100点仍然可以。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.