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

Posted by devguy on Stack Overflow See other posts from Stack Overflow or by devguy
Published on 2009-03-10T09:18:14Z Indexed on 2010/04/28 3:03 UTC
Read the original article Hit count: 291

Filed under:
|

I have a small app that allows the user to draw on the screen with the finger. Yes, nothing original, but it's part of something larger :) I have a UIImageView where the user draws, by creating a CGContextRef and the various CG draw functions. I primarily draw strokes/lines with the function CGContextAddLineToPoint

Now the problem is this: the user can draw lines of various colors. I want to give him the ability to use a "rubber" tool to delete some part of the image drawn so far, with the finger. I initially did this by using a white color for the stroke (set with the CGContextSetRGBStrokeColor function) but it did't work out...because I discovered later that the UIImage on the UIImageView was actually with transparent background, not white...so I would end up with a transparent image with white lines on it!

Is there anyway to set a "transparent" stroke color...or is there any other way to clear the content of the CGContextRef under the user's finger, when he moves it? Thanks

© Stack Overflow or respective owner

Related posts about iphone

Related posts about draw