views:

851

answers:

2

i have a view with uimageview and an image set to it. i want to erase image as something like we do in photoshop with an eraser.how do i achieve this.also how do i undo erase???

A: 

If you know what area you want to erase, you can create a new image of the same size, set the mask to the full image minus the area you want to erase, draw the full image into the new image, and use that as the new image. To undo, simply use the previous image.

Edit

Sample code. Say the area you want to erase from image view imgView is specified with by erasePath:

- (void) clipImage {
  UIImage *img = imgView.image;
  CGSize s = img.size;
  UIGraphicsBeginImageContext(s);
  CGContextRef g = UIGraphicsGetCurrentContext();
  CGContextAddPath(g,erasePath);
  CGContextAddRect(g,CGRectMake(0,0,s.width,s.height));
  CGContextEOClip(g);
  [img drawAtPoint:CGPointZero];
  imageView.image = UIGraphicsGetImageFromCurrentImageContext();
  UIGraphicsEndImageContext();
}
Ed Marty
can you post a sample source code for this
Rahul Vyas
A: 

he dear, please let me know how you creating the erase path

Om Prakash