开发者

how to erase uiimageview and its subviews?

开发者 https://www.devze.com 2023-02-17 04:47 出处:网络
i want to erase image in view (like erase drawing with Eraser).i did if view frame is 0,0,320,480 ,but i worry if the view frame has different size:

i want to erase image in view (like erase drawing with Eraser).i did if view frame is 0,0,320,480 ,but i worry if the view frame has different size:

here my code:

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(UIGraphicsGetCurrentCont开发者_StackOverflowext());
myImageView.image = UIGraphicsGetImageFromCurrentImageContext();


Try the below code ..

    UIGraphicsBeginImageContext(self.frame.size);
    [imageView.image drawInRect:CGRectMake(0, 0, imageView.frame.size.width, imageView.frame.size.height)]; 
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); 
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 30.0);
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 1.0, 1.0, 1.0); 
    CGContextBeginPath(UIGraphicsGetCurrentContext());
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastTouch.x, lastTouch.y);
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
    CGContextStrokePath(UIGraphicsGetCurrentContext());
    imageView.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
0

精彩评论

暂无评论...
验证码 换一张
取 消