【发布时间】:2011-03-17 10:30:39
【问题描述】:
我想擦除视图中的图像(比如用橡皮擦擦除绘图)。如果视图框架为 0,0,320,480,我会这样做,但我担心视图框架的大小是否不同:
这是我的代码:
UIGraphicsBeginImageContext(self.view.frame.size);
[myImageView.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(),kCGImageAlphaNone);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 10);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1, 0, 0, 10);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), point.x, point.y);
//this line code for erasing select the part of the image
CGContextClearRect (UIGraphicsGetCurrentContext(), CGRectMake(point.x, point.y, 30, 30));
//End the code
CGContextStrokePath(UIGraphicsGetCurrentContext());
myImageView.image = UIGraphicsGetImageFromCurrentImageContext();
【问题讨论】:
-
如果您将
UIGraphicsGetCurrentContext()缓存在变量中而不是重复调用它,您的代码将更容易阅读。
标签: iphone cocoa-touch ios4