gpt4 book ai didi

swift - Xcode 8/Swift 3 - 类型 'CGColorRenderingIntent' 没有成员 'RenderingIntentDefault'

转载 作者:行者123 更新时间:2023-11-28 10:18:39 25 4
gpt4 key购买 nike

除了最后一行,我已经成功地将许多错误转换为 Swift 3。它适用于 Xcode 7 但不适用于 Xcode 8。

还值得注意的是,Xcode 7 有关于 CGColorRenderingIntent 的文档,但 Xcode 8 没有。

Type 'CGColorRenderingIntent' has no member 'RenderingIntentDefault'

我正在使用的代码:

import CoreImage

// omitted code

public func imageFromPixels(pixels: ([Pixel], width: Int, height: Int)) -> CIImage {
let bitsPerComponent = 8
let bitsPerPixel = 32
let rgbColorSpace = CGColorSpaceCreateDeviceRGB()
let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.premultipliedLast.rawValue) // alpha is last
let providerRef = CGDataProvider(data: NSData(bytes: pixels.0, length: pixels.0.count * sizeof(Pixel)))
let image = CGImageCreate(pixels.1, pixels.2, bitsPerComponent, bitsPerPixel, pixels.1 * sizeof(Pixel), rgbColorSpace, bitmapInfo, providerRef!, nil, true, CGColorRenderingIntent.RenderingIntentDefault)
return CIImage(CGImage: image!)
}

苹果文档:

enum CGColorRenderingIntent : Int32 {
case RenderingIntentDefault
case RenderingIntentAbsoluteColorimetric
case RenderingIntentRelativeColorimetric
case RenderingIntentPerceptual
case RenderingIntentSaturation
}

更新代码:

let image = CGImage(width: pixels.1,
height: pixels.2,
bitsPerComponent: bitsPerComponent,
bitsPerPixel: bitsPerPixel,
bytesPerRow: pixels.1 * sizeof(Pixel),
space: rgbColorSpace,
bitmapInfo: bitmapInfo,
provider: providerRef!,
decode: nil,
shouldInterpolate: true,
intent: .defaultIntent)

return CGImage(CGImage: image!) // Incorrect argument label in call (have 'CGImage:', expected 'copy:')

最佳答案

⌘-click 符号 CGColorRenderingIntent 你会看到

public enum CGColorRenderingIntent : Int32 {

case defaultIntent
case absoluteColorimetric
case relativeColorimetric
case perceptual
case saturation
}

原来如此

let image = CGImage(width: pixels.1, 
height: pixels.2,
bitsPerComponent: bitsPerComponent,
bitsPerPixel: bitsPerPixel,
bytesPerRow: pixels.1 * sizeof(Pixel),
space: rgbColorSpace,
bitmapInfo: bitmapInfo,
provider: providerRef!,
decode: nil,
shouldInterpolate: true,
intent: .defaultIntent)

return CIImage(cgImage: image!)

甚至 CGImageCIImage 的初始化程序也已更改。

关于swift - Xcode 8/Swift 3 - 类型 'CGColorRenderingIntent' 没有成员 'RenderingIntentDefault',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37911750/

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