//获取相册的所有图片
- (void)reloadImagesFromLibrary
{
self.images = [[NSMutableArray alloc] init];
dispatch_async(dispatch_get_main_queue(), ^{ @autoreleasepool {
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror){
NSLog(@"相册访问失败 =%@", [myerror localizedDescription]);
if ([myerror.localizedDescription rangeOfString:@"Global denied access"].location!=NSNotFound) {
NSLog(@"无法访问相册.请在'设置->定位服务'设置为打开状态.");
}else{
NSLog(@"相册访问失败.");
}
}; ALAssetsGroupEnumerationResultsBlock groupEnumerAtion = ^(ALAsset *result, NSUInteger index, BOOL *stop){
if (result!=NULL) { if ([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto]) { NSString *urlstr=[NSString stringWithFormat:@"%@",result.defaultRepresentation.url];//图片的url
[self.images addObject:urlstr];
//NSLog(@"urlStr is %@",urlstr);
//result.defaultRepresentation.fullScreenImage//图片的大图
//result.thumbnail //图片的缩略图小图
NSRange range1=[urlstr rangeOfString:@"id="];
NSString *resultName=[urlstr substringFromIndex:range1.location+];
resultName=[resultName stringByReplacingOccurrencesOfString:@"&ext=" withString:@"."];//格式demo:123456.png }
}
}; ALAssetsLibraryGroupsEnumerationResultsBlock libraryGroupsEnumeration = ^(ALAssetsGroup* group, BOOL* stop){ if (group == nil)
{ } if (group!=nil) {
NSString *g=[NSString stringWithFormat:@"%@",group];//获取相簿的组
NSLog(@"gg:%@",g);//gg:ALAssetsGroup - Name:Camera Roll, Type:Saved Photos, Assets count:71 NSString *g1=[g substringFromIndex: ] ;
NSArray *arr=[[NSArray alloc] init];
arr=[g1 componentsSeparatedByString:@","];
NSString *g2=[[arr objectAtIndex:] substringFromIndex:];
if ([g2 isEqualToString:@"Camera Roll"]) {
g2=@"相机胶卷";
}
NSString *groupName=g2;//组的name [group enumerateAssetsUsingBlock:groupEnumerAtion];
} }; ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupAll
usingBlock:libraryGroupsEnumeration
failureBlock:failureblock];
} });
}

iOS遍历相册中的图片的更多相关文章

  1. iOS - 选取相册中iCloud云上图片和视频的处理

    关于iOS选取相册中iCloud云上图片和视频  推荐看:TZImagePickerController的源码,这个是一个非常靠谱的相册选择图片视频的库 .当然也可以自己写 如下遇到的问题 工作原因, ...

  2. Android向系统相册中插入图片,相册中会出现两张 一样的图片(只是图片大小不一致)

    向系统相册中插入图片调用此方法时,相册中会出现两张一样的图片 MediaStore.Images.Media.insertImage 一张图片是原图一张图片是缩略图.表现形式为:android4.4. ...

  3. [Xcode 实际操作]九、实用进阶-(12)从系统相册中读取图片

    目录:[Swift]Xcode实际操作 本文将演示从系统相册中读取图片. 在项目导航区,打开视图控制器的代码文件[ViewController.swift] import UIKit //添加两个协议 ...

  4. iOS中获取系统相册中的图片

    一.获取单张图片 思路: 1.利用UIImagePickerController可以从系统自带的App(照片\相机)中获得图片 2.设置代理,遵守代理协议 注意这个UIImagePickerContr ...

  5. iOS 删除相册中照片--来自简书

    来自:http://www.jianshu.com/p/ac18aa3f28c2 最近公司的app有一个新功能是在app中删除相册的照片 ,本来是一个比较简单地功能,在做的过程中却发现AssetsLi ...

  6. Android中使用OKHttp上传图片,从相机和相册中获取图片并剪切

    效果:注意:1:网络权限<;;;); intent.putExtra(); ); intent.putExtra(); intent.putExtra(, byteArrayOutputStre ...

  7. iOS--app自定义相册--从自定义的相册中获取图片

    一.获取单张图片 思路: 1.利用UIImagePickerController可以从系统自带的App(照片\相机)中获得图片 2.设置代理,遵守代理协议 注意这个UIImagePickerContr ...

  8. iOS 从相册中拿到 图片名 ,截取后缀,图片名

    //从路径中获得完整的文件名 (带后缀) 对从相册中取出的图片,视频都有效. NSString *fileName = [filePath lastPathComponent]; //获得文件名 (不 ...

  9. Swift4.0 从相册中获取图片和拍照

    第一步 添加协议 UIImagePickerControllerDelegate,UINavigationControllerDelegate   第二步 添加选择方式 let sexActionSh ...

随机推荐

  1. make[2]: *** No rule to make target `/root/.pyenv/versions/anaconda3-2.4.0/lib/libpython3.5m.so', needed by `evaluation.so'. Stop.

    当出现No rule to make target ,肯定是Makefile有问题. 有的makefile是脚本生成的,你得看脚本的配置文件对不对. 我的是这个脚本生成的.发现是Pythondir的配 ...

  2. 获取B表数据添加到A表中作为一个下拉列表元素存在

    1.ProductController类里toedit方法内添加: ProductModel product = ProductModel.dao.findById(id); //通过id查找服务类 ...

  3. window7下karma 报 nodejs request TypeError: The header content contains invalid characters BUG

    这个BUG 估计只有中国人才 遇到 打开你的依赖node_modules\karma\node_modules\connect\lib\patch.js 将里面的setHeader方法改成下面这样,干 ...

  4. 问题1:Mybatis 中 Signature中的参数args 问题2:MetaObject中 forObject方法中的参数

    1.@Intercepts({@Signature(type =StatementHandler.class, method = "prepare", args ={Connect ...

  5. VC++ 迭代器 iterator, const_iterator, const iterator

    迭代器 iterator, const_iterator, const iterator 迭代器iterator的作用类似于指针. (1)iterator只有针对制定<类型>的容器才有效. ...

  6. C, C#, AS3的变量

    高级语言中变量分值类型和引用类型, C中则分栈和堆, 在作为函数参数传递时,值类型复制,引用类型传递引用,不复制: 高级语言中一些基本类型默认是值类型, 其他基本都是引用类型. C语言中栈和堆变量可以 ...

  7. unity中三种调用其他脚本函数的方法

    第一种,被调用脚本函数为static类型,调用时直接用  脚本名.函数名()第二种,GameObject.Find("脚本所在的物体的名字").SendMessage(" ...

  8. centos7安装mariadb10遇到的问题解决

    4. 安装中的错误 4.1 /bin/ld: cannot find -lz /bin/ld: cannot find -lzcollect2: error: ld returned 1 exit s ...

  9. lua代码设置unity对象的基础属性

    设置对象的父节点: wall.transform:SetParent(GameObject.Find("Walls").transform) 设置颜色: wall:GetCompo ...

  10. LinQ高级查询

    1.模糊查询 con.Users.Where(a =>a.UserName.Contains(name)).ToList(); //包含name con.Users.Where(a =>a ...