gpt4 book ai didi

iphone - 关于图像Alpha值的问题

转载 作者:行者123 更新时间:2023-12-03 21:19:19 25 4
gpt4 key购买 nike

  // Make half-transparent grey, the background color for the layer
UIColor *Light_Grey
= [UIColor colorWithRed : 110/255.0
green : 110/255.0
blue : 110/255.0
alpha : 0.5];

// Get a CGColor object with the same color values
CGColorRef cgLight_Grey = [Light_Grey CGColor];
[boxLayer setBackgroundColor : cgLight_Grey];

// Create a UIImage
UIImage *layerImage = [UIImage imageNamed : @"Test.png"];

// Get the underlying CGImage
CGImageRef image = [layerImage CGImage];

// Put the CGImage on the layer
[boxLayer setContents : (id) image];

考虑上面的示例代码段。

UIColor *Light_Grey 设置的 Alpha 值为 0.5。我的问题是:我是否可以设置 CGImageRef 图像 的 alpha 值?

我问这个问题的原因是,尽管 boxLayer 的 alpha 值为 0.5,但在 BoxLayer 之上设置的任何图像似乎都有 1 的 alpha 默认值,这会掩盖图像正下方的任何内容。

希望有这方面知识的人可以帮忙。

最佳答案

看来您可以使用 CGImageCreate 进行复制并使用解码数组重新缩放 Alpha(例如 0.0-0.5)

decode

The decode array for the image. If you do not want to allow remapping of the image’s color values, pass NULL for the decode array. For each color component in the image’s color space (including the alpha component), a decode array provides a pair of values denoting the upper and lower limits of a range. For example, the decode array for a source image in the RGB color space would contain six entries total, consisting of one pair each for red, green, and blue. When the image is rendered, Quartz uses a linear transform to map the original component value into a relative number within your designated range that is appropriate for the destination color space.

关于iphone - 关于图像Alpha值的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6342779/

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