简体   繁体   English

如何将CVPixelBuffer / CVImageBuffer转换为数据?

[英]How do I convert a CVPixelBuffer / CVImageBuffer to Data?

My camera app captures a photo, enhances it in a certain way, and saves it. 我的相机应用程序会捕获照片,以某种方式对其进行增强并保存。

To do so, I get the input image from the camera in the form of a CVPixelBuffer (wrapped in a CMSampleBuffer). 为此,我以CVPixelBuffer的形式(包装在CMSampleBuffer中)从摄像机获取了输入图像。 I perform some modifications on the pixel buffer, and I then want to convert it to a Data object. 我对像素缓冲区进行了一些修改,然后将其转换为Data对象。 How do I do this? 我该怎么做呢?

Note that I don't want to convert the pixel buffer / image buffer to a UIImage or CGImage since those don't have metadata (like EXIF). 请注意,我不想将像素缓冲区/图像缓冲区转换为UIImage或CGImage,因为它们没有元数据(如EXIF)。 I need a Data object. 我需要一个数据对象。 How do I get one from a CVPixelBuffer / CVImageBuffer? 如何从CVPixelBuffer / CVImageBuffer中获得一个?


PS: I tried calling AVCapturePhotoOutput.jpegPhotoDataRepresentation() but that fails saying "Not a JPEG sample buffer". PS:我尝试调用AVCapturePhotoOutput.jpegPhotoDataRepresentation()但是失败了,提示“不是JPEG样本缓冲区”。 Which makes sense since the CMSampleBuffer contains a pixel buffer (a bitmap), not a JPEG. 这很有意义,因为CMSampleBuffer包含像素缓冲区(位图),而不是JPEG。

如您所说,您可以获取CMSampleBuffer ,则可以使用来获取它

NSData *myata = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:<your_cmsample_buffer_obj‌​>];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM