代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
ObjC
】
获取相册的所有相片
作者:
茶壶
/ 发布于
2015/6/29
/
1279
//获取相册的所有图片 - (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+3]; // 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:16 ] ; NSArray *arr=[[NSArray alloc] init]; arr=[g1 componentsSeparatedByString:@","]; NSString *g2=[[arr objectAtIndex:0] substringFromIndex:5]; 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]; } }); } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. images = [[NSMutableArray alloc] init]; [[GetImageModel defaultModel] reloadImagesFromLibrary]; UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button setFrame:CGRectMake(50, 50, 100, 30)]; [button setTitle:@"Get Images" forState:UIControlStateNormal]; [button addTarget:self action:@selector(logImages) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button]; imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 100, self.view.frame.size.width, self.view.frame.size.height - 100)]; [imageView setContentMode:UIViewContentModeScaleAspectFit]; [self.view addSubview:imageView]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)logImages { images = (NSMutableArray*)[[GetImageModel defaultModel] images]; NSLog(@"images is %@",images); [self getImage:[images objectAtIndex:10]]; } - (void)getImage:(NSString *)urlStr { ALAssetsLibrary *assetLibrary=[[ALAssetsLibrary alloc] init]; NSURL *url=[NSURL URLWithString:urlStr]; [assetLibrary assetForURL:url resultBlock:^(ALAsset *asset) { UIImage *image=[UIImage imageWithCGImage:asset.thumbnail]; imageView.image=image; }failureBlock:^(NSError *error) { NSLog(@"error=%@",error); }]; }
试试其它关键字
获取相册
所有相片
同语言下
.
根据生日计算星座
.
精简的实现一个内存池
.
iOS索引搜索核心代码
.
iOS 搜索框
.
文件操作
.
UIWebView 加载本地网页
.
取消导航条对视图的影响
.
利用终端显示 隐藏文件
.
更改导航条背景颜色
.
iOS 字体斜体
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
茶壶
贡献的其它代码
(
9
)
.
毛玻璃效果
.
整数N随机分成n份
.
如何实现获取当前定位信息
.
获取相册的所有相片
.
plist基本操作
.
获取客户端真实ip地址
.
仿async的 并行执行和序列执行函数
.
二元搜索
.
图的遍历
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3