【问题标题】:Access Burst Mode photos in library访问图库中的连拍模式照片
【发布时间】:2013-12-27 10:04:43
【问题描述】:

我正在尝试访问用户使用连拍模式拍摄的 iOS 资源库中的照片。我正在尝试使用ALAssetsLibrary 并过滤照片:

- (void)findBurstModePhotos
{
    ALAssetsFilter *allPhotos = [ALAssetsFilter allPhotos];

    ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc] init];

    [assetLibrary enumerateGroupsWithTypes:ALAssetsGroupAll
                                usingBlock:^(ALAssetsGroup *group,
                                             BOOL *stop) {
                                    [group setAssetsFilter:allPhotos];

                                    NSLog(@"Group: %@",
                                          [group valueForProperty:
                                           ALAssetsGroupPropertyName]);

                                    if ([group numberOfAssets] > 0) {
                                        [self evaluateGroup:group];
                                    }
                                }
                              failureBlock:^(NSError *error) {
                                  NSLog(@"Failure enumerating groups: %@",
                                        [error localizedDescription]);
                              }];
}

- (void)evaluateGroup:(ALAssetsGroup *)group
{
    [group enumerateAssetsUsingBlock:^(ALAsset *result,
                                       NSUInteger index,
                                       BOOL *stop) {
        NSLog(@"Photo date: %@", [result valueForProperty:ALAssetPropertyDate]);
    }];
}

不幸的是,这会将连拍模式照片作为单张照片返回。是否有支持单独获取连拍模式照片的方法?我想从单个 Burst Mode 会话中获取每张照片。

【问题讨论】:

  • 您可能已经验证了这一点,但我希望您没有删除所有其他版本的照片,除了在连拍模式下最喜欢的照片。
  • 猜对了,但我没有删除其他版本的照片。
  • 这更像是一个问题——但是当您检查 *result 的属性 ALAssetPropertyType 时,它是否报告为 ALAssetTypePhoto?我问是因为我想知道他们是否还没有记录一个新的 ALAssetType(在意想不到的情况下,使用这些类型的 API 尚未完全实现)。
  • 是的,所有照片。我尝试删除 ALAssetsFilter 并寻找所有类型,但没有运气。
  • 我没有机会只保存一个是否只是 5 / 5S 的差异?看来我将所有照片都作为单独的照片。

标签: ios alassetslibrary alasset alassetsgroup


【解决方案1】:

据我了解,Burst Mode 照片将一张一张添加到图库中。每张图片的ALAssetProperty 类型将为ALAssetTypePhoto。因此您可以使用下面的 ALAsset 块单独获取每张照片。因为ALAssetsGroupTypes 只有 7 种类型,ALAssetsFilters 有 3 种类型,您不能一次只检索 Burst Mode 照片集。他们都没有处理连拍模式的照片。

希望苹果以后能提供连拍照片过滤功能。

---------------------------- ALAssetsGroupType -------------------------------------------

ALAssetsGroupLibrary      // The Library group that includes all assets.
ALAssetsGroupAlbum        // All the albums synced from iTunes or created on the device.
ALAssetsGroupEvent        // All the events synced from iTunes.
ALAssetsGroupFaces        // All the faces albums synced from iTunes.
ALAssetsGroupSavedPhotos  // The Saved Photos album.
ALAssetsGroupPhotoStream  // The PhotoStream album.
ALAssetsGroupAll          // The same as ORing together all the available group types,with the exception that ALAssetsGroupLibrary is not included.


-------------------------- ALAssetsFilter ------------------------------------------------

+ (ALAssetsFilter *)allPhotos; // Get all photos assets in the assets group.
+ (ALAssetsFilter *)allVideos; // Get all video assets in the assets group.
+ (ALAssetsFilter *)allAssets; // Get all assets in the group.

使用以下代码分别获取每张照片,包括连拍模式照片,

- (void)findBurstModePhotos
{
    ALAssetsLibrary *assetLibrary = [ViewController defaultAssetsLibrary];

    [assetLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop)
    {
    [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {

      if(result)
      {
        [self evaluateGroup:group];
      }

    }];

    } failureBlock:^(NSError *error) {
        NSLog(@"Error loading images %@", error);
    }];
}

- (void)evaluateGroup:(ALAssetsGroup *)group
{
    [group enumerateAssetsUsingBlock:^(ALAsset *result,
                                       NSUInteger index,
                                       BOOL *stop) {
        NSLog(@"Photo date: %@", [result valueForProperty:ALAssetPropertyDate]);
    }];
}

+ (ALAssetsLibrary *)defaultAssetsLibrary
{
    static dispatch_once_t pred = 0;
    static ALAssetsLibrary *library = nil;
    dispatch_once(&pred, ^{
        library = [[ALAssetsLibrary alloc] init];
    });
    return library;
}

输出日志:

Photo date: 2013-05-06 15:57:21 +0000 //non burst image.
Photo date: 2013-05-06 15:57:41 +0000 //non burst image.
Photo date: 2013-12-20 21:10:40 +0000 //burst image.
Photo date: 2013-12-20 21:10:41 +0000 //burst image.
Photo date: 2013-12-20 21:10:41 +0000 //burst image.
Photo date: 2013-12-20 21:10:41 +0000 //burst image.
Photo date: 2013-12-20 21:10:41 +0000 //burst image.
Photo date: 2013-12-20 21:10:42 +0000 //burst image.
Photo date: 2013-12-20 21:10:42 +0000 //burst image.
Photo date: 2013-12-20 21:10:42 +0000 //burst image.
Photo date: 2013-12-20 21:10:43 +0000 //burst image.
Photo date: 2013-12-20 21:10:43 +0000 //burst image.
Photo date: 2013-12-20 21:10:43 +0000 //burst image.
Photo date: 2013-12-20 21:10:44 +0000 //burst image.
Photo date: 2013-12-20 21:10:44 +0000 //burst image.
Photo date: 2013-12-20 21:10:44 +0000 //burst image.
Photo date: 2013-12-20 21:10:44 +0000 //burst image.
Photo date: 2013-12-20 21:10:45 +0000 //burst image.
Photo date: 2013-12-20 21:10:45 +0000 //burst image.
Photo date: 2013-12-20 21:10:45 +0000 //burst image.
Photo date: 2013-12-20 21:10:45 +0000 //burst image.
Photo date: 2013-12-20 21:10:46 +0000 //burst image.

注意:

如果 Burst Mode 照片捕获相机是您应用程序的一部分,则在将捕获的照片保存到照片库时存储 ALAsset URL's。您可以通过 ALAsset 库使用保存的 ALAsset URL's 检索此照片.

【讨论】:

  • 您拍摄这些照片时使用的是什么设备?使用类似的代码,我只能在 iPhone 5s 上获得一张照片。
  • 您是否将所有照片都保存到相册中?使用任何 3rd 方应用程序来捕获它?还是使用默认相机?
  • 另外你的代码和我的有点不同。把你的代码更新为我的,检查结果并回复我。另外我希望你能在你的设备照片库中看到所有的连拍模式图片。请确认。
  • 这与我的答案基本相同,但解决方案不太完整。
  • @Ramshad 所以您的解决方案基本上是检查时间戳以查看图像是否紧密结合在一起?如果这就是我们所拥有的一切——那么我真的希望苹果在不久的将来能对此有所作为。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-22
  • 1970-01-01
  • 1970-01-01
  • 2022-06-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多