Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
325 views
in Technique[技术] by (71.8m points)

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

I have a small app that allows the user to draw on the screen with the finger. 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 my issue 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 didn't work out...because I discovered later that the UIImage on the UIImageView actually had a 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This will do the trick:

CGContextSetBlendMode(context, kCGBlendModeClear)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...