我试图在Swift中创建一个IOSurface,然后用它创建一个CIImage。IOSurfaceRef看起来不错,但是CIImage返回零:
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初始化器需要更多的元数据来完成它的工作,但我不知道是什么。
发布于 2018-09-20 13:49:39
我的像素格式字节顺序错了。它应该是:
for c in macPixelFormatString.utf8.reversed()由于我不认为在stackoverflow上的Swift中使用IOSurfaceCreate的其他例子,所以这个问题就没有了。
https://stackoverflow.com/questions/52422032
复制相似问题