如何将图片的 .raw 或原始字节存储到没有 png 或 jpeg 表示的本地磁盘文档文件夹

How to store .raw or raw bytes of pictures to local disk documents folder without png or jpeg representation

我想使用 AVCaptureSession 存储捕获图片的原始字节。但是我只看到了pngrepresentation和jpegrepresentation的例子。我想将原始数据字节存储在 phone 的本地磁盘文件中,以便其他时间重新打开它并转换为 UIImage 以进行 post 处理。有没有办法做到这一点? 例如:

CVPixelBufferLockBaseAddress(pixelBuffer, 0);
GLubyte *rawImageBytes = CVPixelBufferGetBaseAddress(pixelBuffer);

我可以将 rawImageBytes 存储在文档中以便稍后打开吗?

当然可以。创建一个包含您的字节的 NSData 对象,并使用 NSData 文件保存方法之一保存该对象(例如 writeToURL:atomically:。)

不过您需要知道 pixelBuffer 中的字节数。看起来您应该使用 CVPixelBufferGetDataSize 来获取字节数。