如何使用蒙版来打出我的图像?
我有一个蒙版(从 256 灰色 PNG 加载),我想将其应用到用作绘制 UITableViewCell
的 过程的一部分的图像>imageView.image
属性。
当单元格未被选择/突出显示时,我使用正确颜色和遮罩的正方形来CGImageCreateWithMask
,然后将drawAtPoint:
它放入我正在构建的图像中。这很好用。
但是,当选择或突出显示单元格时,我想改用蒙版来适当地穿透我的图像。也就是说,当我的蒙版指定完全不透明时,我希望我正在构建的图像完全透明,以便通过它绘制表格视图的背景。当我的蒙版指定 0 不透明度时,我希望 alpha 通道保持不变。除了 alpha 通道受到影响之外,我不希望其他任何东西受到影响。
我想我的意思是我想在 UIImage
上绘制clearColor,并根据蒙版具有不同级别的不透明度。
首先,这叫什么?第二,我该怎么做?
I have a mask (loaded from a 256 grey PNG) that I want to apply to an image that's being used as part of my process for drawing a UITableViewCell
's imageView.image
property.
When the cell isn't selected/highlighted, I CGImageCreateWithMask
with a square of the proper color and the mask, then drawAtPoint:
it into the image I'm building. This works fine.
However, when the cell is selected or highlighted, I'd like to instead use the mask to instead punch through my image appropriately. That is, when my mask specifies full opacity, I want the image I'm building to be completely transparent so the tableview's background is drawn through it. Where my mask specifies 0 opacity, I want the alpha channel untouched. I want nothing other than the alpha channel affected.
I guess what I mean is that I want to draw clearColor over a UIImage
, with a varying level of opacity according to a mask.
First, what is this called? And second, how do I do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你必须为此操纵 CALayers。您可以使用单元格的 CALayer 的 mask 属性: CALayer 掩码属性。
也就是说,有一些阻碍(如果 myMask 是 UIView 的后代):
I think you have to manipulate the CALayers for that. You can use the mask property of the cell's CALayer : CALayer mask attribute.
That is, something in the way of (if myMask is descendent of UIView) :