Мне нужно сохранить необработанные данные с камеры iOS в облако. Я получаю CVPixelBuffer
с камеры iOS. Я не указываю, в каком формате (kCVPixelBufferPixelFormatTypeKey
) я хочу использовать CVPixelBuffer
при настройке камеры iOS.
Я превращаю 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
?