Swift 除CGContextDrawImage外访问CIImage或CGImage位图
我想得到一幅图像的各个像素的RGB值(实际上,提供的图像是灰度的,所以灰度信息就足够了) 我目前拥有以下代码:Swift 除CGContextDrawImage外访问CIImage或CGImage位图,swift,performance,bitmapdata,ciimage,cgcontextdrawimage,Swift,Performance,Bitmapdata,Ciimage,Cgcontextdrawimage,我想得到一幅图像的各个像素的RGB值(实际上,提供的图像是灰度的,所以灰度信息就足够了) 我目前拥有以下代码: // // Conversion of CIImage to CGImage // func convertCIImageToCGImage(inputImage: CIImage) -> CGImage! { return CIContext(options: nil).createCGImage(inputImage, fromRect: inputIma
//
// Conversion of CIImage to CGImage
//
func convertCIImageToCGImage(inputImage: CIImage) -> CGImage! {
return CIContext(options: nil).createCGImage(inputImage, fromRect: inputImage.extent)
}
process(image: CGImage) {
let img=convertCIImageToCGImage(image)
// Set image width, height
width = CGImageGetWidth(img)
height = CGImageGetHeight(img)
let colorSpace = CGColorSpaceCreateDeviceRGB()
let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.PremultipliedFirst.rawValue)
// Create the bitmap context (ARGB)
context = CGBitmapContextCreate(nil, width, height, 8, bitmapBytesPerRow, colorSpace, bitmapInfo.rawValue)!
// draw the image onto the context
let rect = CGRect(x: 0, y: 0, width: width, height: height)
CGContextDrawImage(context, rect, img)
let uncasted_data = CGBitmapContextGetData(context)
data = UnsafePointer<UInt8>(uncasted_data)
...
}
有没有其他方法可以访问CIImage或CGImage的位图?这里有很多来自不同时区的人。即使是“问候,人类”也不够笼统pHa,虽然不能复制和粘贴,忘记粘贴第一行。。。早上好,来自瑞士!
CGContextDrawImage(context, rect, img)