CGImageCreate在swift中给出了错误

Raj*_*ppu 7 pixels ios swift

我正在尝试将图像的像素绘制到图形上下文中以迭代和打印图像的颜色空间信息值.我已设法缓冲所有原始像素值.但我尝试使用CGImageCreate绘制位图图像时遇到以下错误,也附带截图.这是我编写的代码.

func createRGBAPixel(inImage: CGImageRef) -> CGContextRef {
//Image width, height

let pixelWidth = CGImageGetWidth(inImage)
let pixelHeight = CGImageGetHeight(inImage)

//Declaring number of bytes 

let bytesPerRow = Int(pixelWidth) * 4
let byteCount = bytesPerRow * Int(pixelHeight)

//RGB color space

let colorSpace = CGColorSpaceCreateDeviceRGB()

//Allocating image data

let mapData = malloc(byteCount)
let mapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.PremultipliedFirst.rawValue)

//Create bitmap context

let context = CGBitmapContextCreate(mapData, pixelWidth, pixelHeight, Int(8), Int(bytesPerRow), colorSpace, mapInfo.rawValue)

let imageRef = CGBitmapContextCreateImage(context)


CGContextDrawImage(context, CGRectMake(0, 0, pixelWidth, pixelHeight), imageRef)


let data = CGDataProviderCopyData(CGImageGetDataProvider(imageRef)) as! NSData
let pixels = UnsafePointer<UInt8>(data.bytes)
var newPixelsArray = [UInt8](count: byteCount, repeatedValue: 0)
let provider = CGDataProviderCreateWithData(nil , &newPixelsArray, data.length, nil)
let newImageRef = CGImageCreate(pixelWidth, pixelHeight, CGImageGetBitsPerComponent(imageRef), CGImageGetBitsPerPixel(imageRef), bytesPerRow, colorSpace, mapInfo, provider, nil, false, kCGRenderingIntentDefault)


return context!
Run Code Online (Sandbox Code Playgroud)

CGImageCreate在"kCGRenderingIntentDefault"中给出"未解析的标识符"的错误.我也导入了coreGraphics,它在这个地方不接受任何价值.可以提出什么建议?

请帮忙.

Gle*_*wes 7

由于Swift SDK对此类枚举的作用,您必须使用.defaultIntent替换kCGRenderingIntentDefault,如下所示:

let newImageRef = CGImageCreate(pixelWidth, pixelHeight, CGImageGetBitsPerComponent(imageRef), CGImageGetBitsPerPixel(imageRef), bytesPerRow, colorSpace, mapInfo, provider, nil, false, .defaultIntent)
Run Code Online (Sandbox Code Playgroud)