gpt4 book ai didi

ios - 如何在 Swift 中创建 IOSurface

转载 作者:行者123 更新时间:2023-11-28 05:52:29 32 4
gpt4 key购买 nike

我正在尝试在 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 初始化程序需要更多的元数据来完成它的工作,但我不知道是什么。

最佳答案

我弄错了像素格式字节顺序。应该是:

for c in macPixelFormatString.utf8.reversed()

留下这个问题,因为我认为在 stackoverflow 上没有任何其他在 Swift 中使用 IOSurfaceCreate 的例子。

关于ios - 如何在 Swift 中创建 IOSurface,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52422032/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com