我怎样才能消除擦除UIImage

时间:2012-12-27 12:30:33

标签: iphone objective-c ios uiimageview uiimage

  

可能重复:
  How to Unerase the erased UIImage

嗨大家我正在PanGesture中尝试图像擦除代码 我正在使用以下代码:

 UIImage * image  = [UIImage imageNamed:@"326d4fb72362a2e44659141cadfc4977.jpg"];
 holderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 235)];
 imgForeground = [[UIImageView alloc] initWithFrame:[holderView frame]];
 [imgForeground setImage:image];
 [holderView addSubview:imgForeground];


 UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
 [panRecognizer setMinimumNumberOfTouches:1];
 [panRecognizer setMaximumNumberOfTouches:1];
 [panRecognizer setDelegate:self];
 [holderView addGestureRecognizer:panRecognizer];
 [self.view addSubview:holderView];

然后我在这里处理

 -(void)move:(id)sender {

    CGPoint currentPoint;
    if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateBegan){

        lastPoint =  [sender locationInView:imgForeground];
        lastPoint.y -=20;
    }
    else{

        currentPoint = [sender locationInView:imgForeground];;
        currentPoint.y -=20;
    }


    UIGraphicsBeginImageContext(imgForeground.frame.size);
    [imgForeground.image drawInRect:CGRectMake(imgForeground.frame.origin.x, imgForeground.frame.origin.y, imgForeground.frame.size.width, imgForeground.frame.size.height)];

    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetLineCap(context,kCGLineCapRound); //kCGImageAlphaPremultipliedLast);
    CGContextSetLineWidth(context, 10);
    CGContextSetRGBStrokeColor(context, 0, 0, 0, 1.0);
    CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeClear);
    CGContextBeginPath(context);
    CGContextMoveToPoint(context, lastPoint.x, lastPoint.y);
    CGContextAddLineToPoint(context, lastPoint.x, lastPoint.y);
    CGContextStrokePath(context);
    imgForeground.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

 }

我的问题是如何取消图片请帮助

0 个答案:

没有答案
相关问题