美文网首页
获取相册GIF

获取相册GIF

作者: 06f43b0b52f7 | 来源:发表于2017-04-18 00:31 被阅读15次

http://blog.csdn.net/gdutxzy/article/details/44126437

-(void)loadgif
{
NSMutableArray *Imgarr = [NSMutableArray array];
libary = [[ALAssetsLibrary alloc]init];
// ALAssetsGroupAll 取得全部类型
[libary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {

    if(group != Nil)
    {
        //2.再通告文件夹遍历其中的资源文件
        [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
            //index就是他的位置
            //ALAsset 的这个result 就是我们要的图片
            //两种情况
            //单选的话,这个界面是自带的
            //多选的话,没有提供界面,但是提供了照片的资源,我们可以创建一个tableview来弄
            //这个地方我们一般是找一个model或者数组来接受
            //用数组保存起来
            
            if(result != nil)
            {
                // 照片
            if ([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto])
            {
                NSString *fileName = [[result defaultRepresentation] filename];
                
                
                int64_t fileSize = [[result defaultRepresentation] size];
                //取得缩略图
                CGImageRef cmimg = [result thumbnail];
                UIImage * img = [UIImage imageWithCGImage:cmimg];
                YC_PlayMD *model = [[YC_PlayMD alloc]init];
                model.path = fileName;
                model.fullPath = fileName;
                model.length = [NSNumber numberWithFloat:fileSize/1024.0/1024.0];
                model.SfileType = 1;
                model.capImg = img;
                model.selected = [NSNumber numberWithInt:0];
                model.curAsset = result;
                if([fileName hasSuffix:@".GIF"])
                {
                                    
                [Imgarr addObject:model];
                    
                }
                
              
            }

        }
    }];
     self.imgdataSource = [NSMutableArray arrayWithArray:Imgarr];
       
    [self.giftableView reloadData];
}

} failureBlock:^(NSError *error) {

}];
}

相关文章

网友评论

      本文标题:获取相册GIF

      本文链接:https://www.haomeiwen.com/subject/zxgxzttx.html