2

I've got some live photos created JPEG and MOV files, now i want to import them into the app that would allow the user to save the live photos to their photo library. How can i go about doing this?

I've looked into this: https://github.com/genadyo/LivePhotoDemoSwift Which basically allows you to record video and turn it into a live photo. But since i've already created the "live photos", can i save them to the camera roll right away or do i need to follow a different route?

4

1 回答 1

4

您可以使用 LivePhoto 中的单独元素创建 LivePhoto PHLivePhoto.requestLivePhotoWithResourceFileURLs,然后您可以将其保存到库中。

func makeLivePhotoFromItems(imageURL: NSURL, videoURL: NSURL, previewImage: UIImage, completion: (livePhoto: PHLivePhoto) -> Void) {
    PHLivePhoto.requestLivePhotoWithResourceFileURLs([imageURL, videoURL], placeholderImage: previewImage, targetSize: CGSizeZero, contentMode: PHImageContentMode.AspectFit) {
        (livePhoto, infoDict) -> Void in
        if let lp = livePhoto {
            completion(livePhoto: lp)
        }
    }
}

makeLivePhotoFromItems(imgURL, videoURL: movURL, previewImage: prevImg) { (livePhoto) -> Void in
    // "livePhoto" is your PHLivePhoto object, save it/use it here
}

您将需要 JPEG 文件 URL、MOV 文件 URL 和“预览”图像(通常只是 JPEG 或更轻的版本)。

在 Playground 中工作的完整示例。

于 2016-02-23T09:24:36.567 回答