保存已创建的实时照片 [英] Saving Already Created Live Photos
问题描述
我有一些实时照片创建JPEG和MOV文件,现在我想将它们导入应用程序,允许用户将实时照片保存到他们的照片库。我怎么能这样做呢?
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?
我看过这个: https://github.com/genadyo/LivePhotoDemoSwift 这基本上允许您录制视频并将其转换为实时照片。但是因为我已经创建了实时照片,我可以立即将它们保存到相机胶卷中还是我需要遵循不同的路线?
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?
推荐答案
您可以使用 PHLivePhoto.requestLivePhotoWithResourceFileURLs
从LivePhoto中的单独元素创建LivePhoto,然后您就可以将其保存到库中。
You can create a LivePhoto from separate elements from a LivePhoto by using PHLivePhoto.requestLivePhotoWithResourceFileURLs
, you will then be able to save it to the library.
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或更轻的版本)。
You will need the JPEG file URL, the MOV file URL, and a "preview" image (which is usually just the JPEG or a lighter version of it).
在游乐场中工作的完整示例此处。
Full example working in a Playground here.
这篇关于保存已创建的实时照片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!