AVFoundation保存照片应用内应用比使用照片应用程序保存大3-4倍

时间:2017-08-14 15:08:47

标签: ios swift avfoundation

我使用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只是数据。

0 个答案:

没有答案