我有一个UIImageView,它是我画的点。我将CGpoint存储在容量为100的NSArray中。每次收到新的CGpoint时,我都想从数组中删除最后一个对象,从数组中删除它,然后绘制新的CGpoint并将其添加到数组中。
那么我如何擦除CGpoint呢?只有100 CGpoint在我的UIImageView上
我的代码:
- (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();
}发布于 2015-05-25 13:30:45
不能从图像中移除点。这是一张图片--想象它就像你拍的照片,然后你试着从照片中移除背景。不可能的。
最好的做法是不要使用双缓冲区--只需将数组中的点保持在数组中,并在需要时将它们全部绘制出来。那你就不用移除任何东西了。这是真的,这可能会影响一点的表现,但100分应该仍然是好的。
https://stackoverflow.com/questions/30439383
复制相似问题