来自iOS相机的原始图像数据格式

时间:2019-01-18 19:43:41

标签: ios swift image-processing core-image

我需要将iOS相机中的原始数据保存到云中。我从iOS相机收到CVPixelBuffer。设置iOS相机时,我没有指定要使用kCVPixelBufferPixelFormatTypeKey的格式(CVPixelBuffer

我将CVPixelBuffer变成这样的Data对象。

let buffer: CVPixelBuffer = //My buffer from the camera

//Get the height for the size calculation
let height = CVPixelBufferGetHeight(buffer)

//Get the bytes per row for the size calculation
let bytesPerRow = CVPixelBufferGetBytesPerRow(buffer)

//Lock the buffer so we can turn it into data
CVPixelBufferLockBaseAddress(buffer, CVPixelBufferLockFlags.readOnly)

//Get the base address. This is the address in memory of where the start of the buffer is currently stored.
guard let pointer = CVPixelBufferGetBaseAddress(buffer) else {
    //If we failed to get the base address unlock the buffer and clean up.
    CVPixelBufferUnlockBaseAddress(buffer, CVPixelBufferLockFlags.readOnly)
    return
}

let data = Data(bytes: pointer, count: height * bytesPerRow)

我这样做正确吗?

此外,当我取回这些数据时,如何将其变成CIImage

0 个答案:

没有答案