+3  A: 

Here's just tossing out an idea:

Instead of drawing the red line directly on the image, I'd duplicate the image, add it as a new layer on top of the original image, and give it a totally transparent mask (so the new layer is "invisible").

Then when the user draws the red line, use that to build a path as a mask on the invisible layer. When the path is finished, fill in the path with black (on the mask), to make that portion totally opaque. You could maybe then resize the top layer (that's been masked) to be the bounding rectangle of the drawn path.

The opaque pixels on the topmost layer will then be the ones that were bounded by the drawn path, and you can then do what you please with it (draw it to a new UIImage, etc).

Hope that makes sense...

Dave DeLong
could you please post a sample source for this
Rahul Vyas
A: 

Take a look at my old sample code project here: Cropped Image

It's for Cocoa, not Cocoa Touch, but the idea is the same. You can crop an image by compositing using the SourceIn compositing mode.

NSResponder
your sample code is excellent.can you tell me how do i show color pallete on iphone then choose a color
Rahul Vyas
I'm a bit surprised that there doesn't seem to be a color picker in the UIKit. I guess you'll have to write one.
NSResponder