0

I hope that makes sense. I'll try to explain it.

I have a UIImageView on screen, and am wondering how I can take the area after "drawing" on it with a finger, and remove that section from the UImage, or, create a separate UIImage from the selection.

I'm not looking for code (unless you have it =] ), just an idea of how to go about doing it. If you have tips, I'd be very grateful, thanks.

5 Answers5

0

If I understand your question, I think I would add a transparent UIView as a subview over the top of the UIImageView. And draw on that. Then you can remove/hide the subview when your done.

zingle-dingle
  • 1,681
  • 16
  • 16
  • Hmm, maybe I wasn't clear? The resulting area that's "drawn" on the image with a finger, should remove that area from the image. Like an eraser. OR, save that selected area as another, separate, UIImage – Brenden Ellingboe Oct 25 '12 at 21:40
0

you need to create a UIGestureRecognizer with target and a action like -imageIsPressed, in this -imagePressed method you can call something to make the image disappear. I would suggest placing the UIImage into a UIImageView and calling imageview.hidden = YES; to hide the image, and set it back to "NO" once its not held by the finger.

Yuliani Noriega
  • 1,085
  • 12
  • 23
  • See my comment below: http://stackoverflow.com/questions/13077204/hide-reveal-uiimage-based-on-finger-path#comment17766713_13077558 looking for a way to "erase" part of an image as you drag your finger across, or select the area, and create a separate image. – Brenden Ellingboe Oct 25 '12 at 21:44
0

You'd need to implement something that captures the area the user 'selected' (maybe be creating a CGPath. Then you create a CALayer of the size of the imageView. In it you create, draw and fill the captured path with some arbitrary color while leaving the rest transparent. Finally you apply your generated CALayer as a mask to the UIImageView:

imageView.layer.mask = maskLayer;

Hope that gets you started.

For more info on how to draw that custom CALayer pls refer to Quartz Programming Guide

Tobi
  • 5,499
  • 3
  • 31
  • 47
0

So basically you want to implement freehand erasing of an image? You will need to use core graphics and the various CGContext methods (with blend mode set to clear) to achieve this. There are two approaches, but both start with drawing your image as the first part of drawRect, and then

1) Store your strokes in an array, and stroke all of them over top of the image.

2) Stroke one stroke over the image and then store the resulting image into a UIImage. Use this UIImage as the next image that you draw in drawRect. This one is difficult for undo/redo functionality.

borrrden
  • 33,256
  • 8
  • 74
  • 109
0

I recently implemented this myself and made the source available here. Basically I used the same methods described here with this change when setting up the graphics context:

CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeClear);
Community
  • 1
  • 1
Nathanial Woolls
  • 5,231
  • 24
  • 32