关闭

ALAssetsGroup详解

186人阅读 评论(0) 收藏 举报
分类:

ALAssetsGroup类是系统用于映射相册资源中的每个相册,可以通过该类获取相册中的资源文件,并且能向相册中添加资源文件

    

    //保存图片到系统默认的相册中,使用cgimageref的形式,并且选择图片以什么旋转方向的形式保存,并返回照片的url地址

    /*
     typedef enum {
     ALAssetOrientationUp,            // default orientation
     ALAssetOrientationDown,          // 180 deg rotation
     ALAssetOrientationLeft,          // 90 deg CCW
     ALAssetOrientationRight,         // 90 deg CW
     ALAssetOrientationUpMirrored,    // as above but image mirrored along other axis. horizontal flip
     ALAssetOrientationDownMirrored,  // horizontal flip
     ALAssetOrientationLeftMirrored,  // vertical flip
     ALAssetOrientationRightMirrored, // vertical flip
     } ALAssetOrientation;
     */

    UIImage* image = [UIImage imageNamed:@"test.png"];
    [_library writeImageToSavedPhotosAlbum:[image CGImage] orientation:ALAssetOrientationLeft completionBlock:^(NSURL *assetURL, NSError *error) {
        NSLog(@"save image:%@",assetURL);
        //通过ALAssetsLibrary迭代取出所有相册
        [_library enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
            NSString* groupname = [group valueForProperty:ALAssetsGroupPropertyName];
            //如果相册的名称是test的时候,对其进行操作
            if ([groupname isEqualToString:@"test"]) {
                //设置相册组的筛选条件,ALAssetsFilter类表示筛选条件,allPhotos代表相册只包含相片,allVideos代表只包含视频,allAssets代表包含所有资源
                [group setAssetsFilter:[ALAssetsFilter allPhotos]];
                //通过刚保存的照片的url,把保存到默认相册的照片也保存到test相册中
                [_library assetForURL:assetURL resultBlock:^(ALAsset *asset) {
                    //添加资源到指定的相册
                    [group addAsset:asset];
                    //获取相册中一共的资源数量
                    int count = [group numberOfAssets];
                    NSLog(@"count:%d",count);
                    dispatch_queue_t main = dispatch_get_main_queue();
                    dispatch_async(main, ^{
                        //获取相册的封面图片
                        CGImageRef poster = [group posterImage];
                        [imageView setImage:[UIImage imageWithCGImage:poster]];
                    });
                    //NSString *const ALAssetsGroupPropertyName;
                    //NSString *const ALAssetsGroupPropertyType;
                    //NSString *const ALAssetsGroupPropertyPersistentID;
                    //NSString *const ALAssetsGroupPropertyURL;
                    //查看相册的名字

                    NSLog(@"ALAssetsGroupPropertyName:%@",[group valueForProperty:ALAssetsGroupPropertyName]);
                    //查看相册的类型
                    NSLog(@"ALAssetsGroupPropertyType:%@",[group valueForProperty:ALAssetsGroupPropertyType]);
                    //查看相册的存储id
                    NSLog(@"ALAssetsGroupPropertyPersistentID:%@",[group valueForProperty:ALAssetsGroupPropertyPersistentID]);
                    //查看相册存储的位置地址
                    NSLog(@"ALAssetsGroupPropertyURL:%@",[group valueForProperty:ALAssetsGroupPropertyURL]);
                    //按遍历顺序获取指定索引的资源,遍历顺序可以是先序或倒序
                    /*
                     enum {
                     NSEnumerationConcurrent = (1UL << 0),
                     NSEnumerationReverse = (1UL << 1),
                     };
                     typedef NSUInteger NSEnumerationOptions;
                     */

                    [group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:0] options:NSEnumerationConcurrent usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
                        
                    }];
                    //按顺便遍历获取相册中所有的资源,index代表资源的索引,stop赋值为false时,会停止遍历
                    [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
                        
                    }];
                     //按顺便遍历获取相册中所有的资源,遍历顺序可以是先序或倒序,index代表资源的索引,stop赋值为false时,会停止遍历
                    [group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
                        
                    }];
                    
                } failureBlock:^(NSError *error) {
                    
                }];
            }
        } failureBlock:^(NSError *error) {
            
        }];
    }];
0
0
查看评论

ALAssetsGroup详解

转载自:http://blog.csdn.net/kingsley_cxz/article/details/9166333 ALAssetsGroup类是系统用于映射相册资源中的每个相册,可以通过该类获取相册中的资源文件,并且能向相册中添加资源文件    ...
  • chenyong05314
  • chenyong05314
  • 2014-04-30 15:13
  • 5406

ALAssetsLibrary,ALAssetsGroup,ALAsset,ALAssetRepresentation用法详解

ALAssetsLibrary被封装在 框架中。所以,我们在使用时,需要引入该框架。 需添加AssetsLibrary.framework  然后引入  #import  #import  #import  ...
  • xuxunno1
  • xuxunno1
  • 2014-05-24 17:20
  • 2415

ALAssetsgroup

ALAssetsgroup --------------------------------------------------------------------------- Enumerating Assets(遍历资源) – enumerateAssetsUsin...
  • xuchaovip
  • xuchaovip
  • 2014-04-10 11:57
  • 525

ALAssetsGroup

ALAssetsGroup类是系统用于映射相册资源中的每个相册,可以通过该类获取相册中的资源文件,并且能向相册中添加资源文件          //保存图片到系统默认的相册中,使用cgimageref的形式,并且选择图片以什么旋转方向的形式保存,...
  • hua_lu_zhao
  • hua_lu_zhao
  • 2015-05-19 14:31
  • 280

ALAssetsGroup failed to add asset: 错误 IOS8

IOS8删除相册后,在写入到同名相册会产生下面这样的错误 Error Domain=LIB_ALAssetsLibrary_CustomPhotoAlbum Code=0 "ALAssetsGroup failed to add asset: ALAsset - Type:Photo...
  • leonpengweicn
  • leonpengweicn
  • 2015-02-04 15:22
  • 1876

iOS --- 使用ALAssetsLibrary访问设备中的所有照片信息

ALAssetsLibrary 提供了访问iOS设备下”照片”应用下所有照片和视频的接口; 从 ALAssetsLibrary 中可读取所有的相册数据,即 ALAssetsGroup 对象列表; 从每个 ALAssetsGroup 中可获取到其中包含的照片或视频列表,即 ALAsset 对象列表...
  • icetime17
  • icetime17
  • 2015-08-30 12:23
  • 2465

ALAsset,ALAssetsLibrary,ALAssetsgroup常见属性及用法

ALAssetsgroup Enumerating Assets(遍历资源) – enumerateAssetsUsingBlock:(用一个block来遍历组里的资源)– enumerateAssetsWithOptions:usingBlock:(在枚...
  • huangmindong
  • huangmindong
  • 2014-06-26 19:53
  • 369

【iOS开发】---- ALAsset,ALAssetsLibrary,ALAssetsgroup常见属性及用法

ALAssetsgroup --------------------------------------------------------------------------- Enumerating Assets(遍历资源) – enumerateAssets...
  • kareily
  • kareily
  • 2014-04-25 11:05
  • 640

关于ios9中得ALAssetsLibrary框架过时问题

用Photos框架代替。 其中:保存视频的代码:         ALAssetsLibrary *assetsLibrary=[[ALAssetsLibrary alloc]init];       ...
  • u011010305
  • u011010305
  • 2015-10-06 16:40
  • 4883

保存(获取)图片到(自定义)相册

保存(获取)图片到(自定义)相册
  • c_chang
  • c_chang
  • 2016-02-16 11:07
  • 1013
    个人资料
    • 访问:165954次
    • 积分:2974
    • 等级:
    • 排名:第14006名
    • 原创:115篇
    • 转载:124篇
    • 译文:3篇
    • 评论:7条
    最新评论