gpt4 book ai didi

ios - Core Graphics 反转 alpha

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:39:46 25 4
gpt4 key购买 nike

目前,我在 Cocos2D 中的 CCClippingNode 和转换中遇到问题,如 here 所述.现在 Viktor(SpriteBuilder 的作者)gave a tip我可以用 Core Graphics 屏蔽图像。

我现在正在做的,而且很有效。然而,Core Graphics 使用与 Cocos2d 完全相反的 alpha 来进行 mask 。是否可以动态反转 UIImage(灰度)的 alpha 值?

如果我想用 Cocos 遮住图像中的圆圈,我需要这个 mask 。

Cocos Mask

但在核心图形中需要这样。

Core Graphics

是否可以从顶部图像即时创建底部图像? (例如反转它的 alpha)

最佳答案

How to convert UIImage/CGImageRef's alpha channel to mask?

Ben 对链接问题的回答解决了给定 UIImage 的反转 alpha。只需删除/注释代码的以下部分

for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
unsigned char val = alphaData[y*strideLength + x];
val = 255 - val;
alphaData[y*strideLength + x] = val;
}

PS:无法添加评论。

关于ios - Core Graphics 反转 alpha,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22710797/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com