-1

Possible Duplicate:
How to draw a transparent stroke (or anyway clear part of an image) on the iPhone

I have a uiimage view on that a transparent layer is there if we make touch on that transparent layer that touched part transparent layer should be erased and should show the image back of it.. how can i do this....? thanks in advance

Community
  • 1
  • 1
08442
  • 521
  • 2
  • 13
  • [What have you tried?](http://www.whathaveyoutried.com) – Charan Sep 08 '12 at 10:03
  • UIImage * backgroundImage = [UIImage imageNamed:@"images.jpeg"]; CALayer* aLayer = [CALayer layer]; CGFloat nativeWidth = CGImageGetWidth(backgroundImage.CGImage); CGFloat nativeHeight = CGImageGetHeight(backgroundImage.CGImage); CGRect startFrame = CGRectMake(0.0, 0.0, nativeWidth, nativeHeight); aLayer.contents = (id)backgroundImage.CGImage; aLayer.frame = startFrame; [self.view.layer addSublayer:aLayer]; - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { ; – 08442 Sep 08 '12 at 10:07
  • @pammu do u want to erase the bit of selected image from the source image? – Arun Sep 08 '12 at 13:39
  • i have a image on that an overlay image is there when i erse the overlay it should show yha part of the image – 08442 Sep 08 '12 at 14:02

1 Answers1

0

For my understanding you want to erase the part of the image by touching... Is that right ?

Try this code for erasing by touches moved part of image....

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    lastTouch = [touch locationInView:canvasView];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    currentTouch = [touch locationInView:canvasView];

    CGFloat brushSize = 35;
    CGColorRef strokeColor = [UIColor whiteColor].CGColor;

    UIGraphicsBeginImageContext(scratchView.frame.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [canvasView.image drawInRect:CGRectMake(0, 0, canvasView.frame.size.width, canvasView.frame.size.height)];
    CGContextSetLineCap(context, kCGLineCapRound);
    CGContextSetLineWidth(context, brushSize);
    CGContextSetStrokeColorWithColor(context, strokeColor);
    CGContextSetBlendMode(context, kCGBlendModeClear);
    CGContextBeginPath(context);
    CGContextMoveToPoint(context, lastTouch.x, lastTouch.y);
    CGContextAddLineToPoint(context, currentTouch.x, currentTouch.y);
    CGContextStrokePath(context);
    canvasView.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    lastTouch = [touch locationInView:canvasView];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

}

I hope this will help you....

Arun
  • 3,406
  • 4
  • 30
  • 55