将颜色应用于灰度图像,保留 alpha 值(iOS/Quartz)
这可能非常简单,但我什至不确定它叫什么 - 这使得谷歌搜索比平常有用一点。
我有一个带有 alpha 的灰度线图,用于抗锯齿效果。该图用作游戏中的玩家令牌。目前,我已经创建了几个彩色变体(在 Photoshop 中)。但我希望能够以编程方式对原始图像进行着色,同时保留 alpha 值。我正在使用 Quartz/Core Graphics,我怀疑可能有某种混合可以实现所需的效果 - 但不确定哪种方法或者即使这是正确的方法。
This is probably very straightforward, but I am not even sure what it's called - which makes googling a bit less useful than usual.
I have a gray scale line drawing with alpha for anti-aliasing effect. This drawing is used as a player token in a game. Currently, I have created a couple of colorized variants (in Photoshop). But I would like to be able to programmatically tint the original image, while preserving the alpha values. I am using Quartz/Core Graphics, and I suspect that there may be some sort of blend that would accomplish the desired effect - but not sure which or even if that's the right approach.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个。
ColorChangingImageView.h:
ColorChangingImageView.m:
然后,使用它:
...或者无论如何,非常接近的东西。让我知道它是否适合您。
您还可以使用 CGContextSetBlendMode() 的第二个参数来获得略有不同的效果。
Try this.
ColorChangingImageView.h:
ColorChangingImageView.m:
Then, to use it:
...or anyway, something very close to that that. Let me know if it works out for you.
You can also play with the second parameter to
CGContextSetBlendMode()
for slightly different effects.