我使用AVFoundation捕捉照片并在本地保存照片。
我使用AVCapturePhotoOutput.jpegPhotoDataRepresentation获取数据,但文件大小与使用Photos框架保存时的大小相比似乎是3-4倍。怎么会这样?
photoData:
photoData = AVCapturePhotoOutput.jpegPhotoDataRepresentation(forJPEGSampleBuffer: photoSampleBuffer, previewPhotoSampleBuffer: previewPhotoSampleBuffer)
使用照片框架保存代码:
PHPhotoLibrary.shared().performChanges({ [unowned self] in
let creationRequest = PHAssetChangeRequest.creationRequestForAsset(from: UIImage(data: photoData)!)
creationRequest.creationDate = Date()
if let assetCollection = assetCollection, let assetPlaceholder = creationRequest.placeholderForCreatedAsset {
let albumChangeRequest = PHAssetCollectionChangeRequest(for: assetCollection)
let enumeration: NSArray = [assetPlaceholder]
albumChangeRequest?.addAssets(enumeration)
}
}, completionHandler: { [unowned self] success, error in
}
)
本地代码保存:
try! photoData.write(to: originalFilePath, options: .atomic)
photoData只是数据。