【发布时间】:2016-06-19 20:55:29
【问题描述】:
除了最后一行之外,我已经成功地将许多错误转换为 Swift 3。它适用于 Xcode 7,但不适用于 Xcode 8。
还值得注意的是,Xcode 7 有关于 CGColorRenderingIntent 的文档,但 Xcode 8 没有。
类型“CGColorRenderingIntent”没有成员“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:')
【问题讨论】:
-
错字:
return CIImage(cgImage: ...with I -
无论您查看什么文档都是旧文档。如果你在谷歌上搜索一个符号并找到以 developer.apple.com/library/ 开头的 URL,那么你就在发布 OS 和 Swift 2 的文档中。Swift 3 / Xcode 8 / associated OS beta docs for that枚举为here。
-
是的,那只是我返回的一种类型。主要问题是找到
CGColorRenderingIntent枚举的案例名称。我总是 cmd-click 任何我遇到的问题,但由于某种原因,我的 Xcode 8 只给我grey question marks或no docs消息。我很惊讶它甚至作为测试版发布,因为每次我更改某些内容时,错误更新需要 10 秒。我每 30 秒点击一次Build,它似乎可以正确显示我的所有错误。每隔几秒钟,我的颜色编码也会消失。 -
您似乎正在使用 Swift Playground 教程进行光线跟踪。自发布以来,语法发生了很大变化。在这种情况下,您能否通过 github 将您完成的代码发送给我?