gpt4 book ai didi

swift - swift 本地保存 MTLTexture 数据

转载 作者:行者123 更新时间:2023-11-28 05:53:21 25 4
gpt4 key购买 nike

MTLTexture 是一种内存分配,用于存储 GPU 可访问的格式化图像数据。我想知道有没有什么方法可以在本地保存 MTLTexture 数据?

如果是这样,在本地保存 MTLTexture 数据的最合适方法是什么?

最佳答案

您可以使用getBytes 函数从纹理中获取图像字节数据:

getBytes(_:bytesPerRow:bytesPerImage:from:mipmapLevel:slice:)

Copies a block of pixels from the storage allocation of a texture slice into system memory at a specified address

https://developer.apple.com/documentation/metal/mtltexture/1516318-getbytes

您可以使用字节创建一个 Data 对象:

Data.init(bytes: UnsafeRawPointer, count: Int)

或者您可以将此数据与 CGCreateImage 一起使用来创建图像。完整示例在这里:

https://github.com/metal-by-example/sample-code/blob/master/objc/14-ImageProcessing/ImageProcessing/UIImage%2BMBETextureUtilities.m

关于swift - swift 本地保存 MTLTexture 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52146672/

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