iphone - 关于图像Alpha值的问题

标签 iphone objective-c cocoa-touch

  // 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/

相关文章:

ios - 带有 UITabBarItem 的主从细节?

cocoa - 如何从其父 View 中删除带有圆角的 UIView?

java - 适用于 Android 和 iPhone 的问卷

iphone - 从 iOS 应用程序将音频上传到 Facebook?

iphone - 想要在 UITableView 中从右向左滑动时显示删除按钮

iphone - iOS - 是否可以获取 iPhone 用户设置的背景图像?

iphone - 如何在 obj-c 中动态地处理控件?

objective-c - Cocoa-Touch - 如何解析本地 Json 文件

ios - 无法将故事发布到 Facebook

iphone - 提交 iphone 应用程序时遇到问题