我正在尝试在Swift中创建一个IOSurface,并从中创建一个CIImage。IOSurfaceRef看起来没问题,但CIImage返回nil:
textureImageWidth = 1024
textureImageHeight = 1024
let macPixelFormatString = "ARGB"
var macPixelFormat: UInt32 = 0
for c in macPixelFormatString.utf8 {
macPixelFormat *= 256
macPixelFormat += UInt32(c)
}
let ioSurface = IOSurfaceCreate([kIOSurfaceWidth: textureImageWidth,
kIOSurfaceHeight: textureImageHeight,
kIOSurfaceBytesPerElement: 4,
kIOSurfaceBytesPerRow: textureImageWidth * 4,
kIOSurfaceAllocSize: textureImageWidth * textureImageHeight * 4,
kIOSurfacePixelFormat: macPixelFormat] as CFDictionary)!
IOSurfaceLock(ioSurface, IOSurfaceLockOptions.readOnly, nil)
let test = CIImage(ioSurface: ioSurface)
IOSurfaceUnlock(ioSurface, IOSurfaceLockOptions.readOnly, nil)
请问有什么建议吗?我猜测 CIImage 初始器需要更多的元数据来完成其工作,但我不知道是什么。
kCVPixelFormatType_32BGRA
来避免手动构造像素格式UInt32。正如您通过反转字符串所发现的那样,kCVPixelFormatType_32BGRA
比kCVPixelFormatType_32ARGB
得到了更广泛的支持。 - Liam Don