Skip to content

Instantly share code, notes, and snippets.

View LucasDang's full-sized avatar

Lucas Chao LucasDang

  • Shanghai
View GitHub Profile
@shalyf
shalyf / CVPixelBuffer(Data).swift
Created July 17, 2018 12:44
CVPixelBuffer转Data,以及Data转CVPixelBuffer
func getData(from pixelBuffer: CVPixelBuffer) -> Data {
//TODO:可以通过CVPixelBufferGetPlaneCount判断一下pixelBuffer是否有两个Plane
CVPixelBufferLockBaseAddress(pixelBuffer, CVPixelBufferLockFlags(rawValue: 0))
let pixelFormatType = CVPixelBufferGetPixelFormatType(pixelBuffer)
let width = CVPixelBufferGetWidth(pixelBuffer)
let height = CVPixelBufferGetHeight(pixelBuffer)
var data = Data()