如何在iPhone上绘制透明笔划(或任何清晰的图像部分) [英] How to draw a transparent stroke (or anyway clear part of an image) on the iPhone

查看:138
本文介绍了如何在iPhone上绘制透明笔划(或任何清晰的图像部分)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小应用程序,允许用户用手指在屏幕上绘图。
我有一个 UIImageView 用户通过创建 CGContextRef 和各种<$ c $来绘制c> CG绘制函数。我主要使用函数 CGContextAddLineToPoint

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

绘制笔画/线条现在我的问题是:
用户可以画出各种颜色的线条。我想让他能够使用橡胶工具用手指删除到目前为止绘制的图像的某些部分。我最初通过使用白色作为笔划(使用 CGContextSetRGBStrokeColor 函数设置)来做到这一点,但它没有用完...因为我后来发现<$ UIImageView 上的c $ c> UIImage 实际上有一个透明的背景,而不是白色...所以我最终会得到一个白色的透明图像就行了!

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!

无论如何设置透明笔触颜色还是有其他方法可以当他移动它时,在用户的手指下清除 CGContextRef 的内容?
谢谢

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

推荐答案

这样做可以解决问题:

CGContextSetBlendMode(context, kCGBlendModeClear)

这篇关于如何在iPhone上绘制透明笔划(或任何清晰的图像部分)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆