API to capture Live Photos in iOS9

2019-03-10 22:53发布

I can't find any API to capture live photos. Did I miss something?

Apple release DOCs

Live Photos

Live Photos is a new feature of iOS 9 that allows users to capture and relive their favorite moments with richer context than traditional photos. When the user presses the shutter button, the Camera app captures much more content along with the regular photo, including audio and additional frames before and after the photo. When browsing through these photos, users can interact with them and play back all the captured content, making the photos come to life.

iOS 9.1 introduces APIs that allow apps to incorporate playback of Live Photos, as well as export the data for sharing. There is new support in the Photos framework to fetch a PHLivePhoto object from the PHImageManager object, which is used to represent all the data that comprises a Live Photo. You can use a PHLivePhotoView object (defined in the PhotosUI framework) to display the contents of a Live Photo. The PHLivePhotoView view takes care of displaying the image, handling all user interaction, and applying the visual treatments to play back the content.

You can also use PHAssetResource to access the data of a PHLivePhoto object for sharing purposes. You can request a PHLivePhoto object for an asset in the user’s photo library by using PHImageManager or UIImagePickerController. If you have a sharing extension, you can also get PHLivePhoto objects by using NSItemProvider. On the receiving side of a share, you can recreate a PHLivePhoto object from the set of files originally exported by the sender.

During the keynote, they mentioned that Facebook will support Live Photos, so I would suspect there has to be a way to capture Live Photos.

标签: ios swift ios9
4条回答
唯我独甜
2楼-- · 2019-03-10 23:39

UIImagePickerController looks like it will allow the capture of live photos.

Working with Live Photos

Live Photos is a Camera app feature on supported devices, enabling a picture to be not just a single moment in time but to include motion and sound from the moments just before and after its capture. A PHLivePhoto object represents a Live Photo, and the PHLivePhotoView class provides a system-standard, interactive user interface for displaying a Live Photo and playing back its content. Live Photos are still photos. When you use an image picker controller to capture or choose still images (by including only the kUTTypeImage type in the mediaTypes array), assets that were captured as Live Photos still appear in the picker. However, when the user chooses an asset, your delegate object receives only a UIImage object containing a still-image representation of the Live Photo. To obtain the full motion and sound content when the user captures or chooses a Live Photo with the image picker, you must include both the kUTTypeImage and kUTTypeLivePhoto types in the the mediaTypes array. For more information, see UIImagePickerControllerLivePhoto in UIImagePickerControllerDelegate Protocol Reference.

https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIImagePickerController_Class/index.html#//apple_ref/occ/cl/UIImagePickerController

查看更多
趁早两清
3楼-- · 2019-03-10 23:40

As per Apple Doc:

UIImagePickerControllerLivePhoto

The Live Photo representation of the selected or captured photo.

A Live Photo is a picture, that includes motion and sound from the moments just before and after its capture. On compatible devices, the Camera app captures all photos as Live Photos by default, but the imagePickerController:didFinishPickingImage:editingInfo: method’s image parameter contains only the still image representation.

To obtain the motion and sound content of a live photo for display (using the PHLivePhotoView class), include the kUTTypeImage and kUTTypeLivePhoto identifiers in the allowed media types when configuring an image picker controller. When the user picks or captures a Live Photo, the editingInfo dictionary contains the UIImagePickerControllerLivePhoto key, with a PHLivePhoto representation of the photo as the corresponding value.

Available in iOS 9.1 and later.

// create an image picker controller instance
    UIImagePickerController *picker = [[UIImagePickerController alloc]init];
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    picker.allowsEditing = NO;
    picker.delegate = self;

    // make sure we include Live Photos (otherwise we'll only get UIImages)
    NSArray *mediaTypes = @[(NSString *)kUTTypeImage, (NSString *)kUTTypeLivePhoto];
    picker.mediaTypes = mediaTypes;

    // bring up the picker
    [self presentViewController:picker animated:YES completion:nil];

And then

# pragma mark - UIImagePickerController Delegate

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{

// check if this is a Live Image, otherwise present a warning
    PHLivePhoto *photo = [info objectForKey:UIImagePickerControllerLivePhoto];
    if (!photo) {
        [self notLivePhotoWarning];
        return;
    }
// create a Live Photo View
    PHLivePhotoView *photoView = [[PHLivePhotoView alloc]initWithFrame:rect];
    photoView.livePhoto =  [info objectForKey:UIImagePickerControllerLivePhoto]; 

}
查看更多
劳资没心,怎么记你
4楼-- · 2019-03-10 23:44

There is no API for manual capture of Live Photos (that is, nothing analogous to the AVCapture APIs that offer direct control for capturing regular photos or video).

UIImagePickerController, which normally presents a UI allowing the user to capture a photo or video, can also capture Live Photos in iOS 9.1 or later. To allow Live Photo capture, set the image picker controller's mediaTypes property to include both kUTTypeImage and kUTTypeLivePhoto.

查看更多
干净又极端
5楼-- · 2019-03-10 23:45

No love in iOS 9, but APIs for taking and editing Live Photos are available in iOS 10.

Here's a talk from WWDC about it all.

查看更多
登录 后发表回答