ALAssetsLibrary使用
2024-08-24 07:58:40
在iOS中,我们调用摄像头和选择相册中的资源,我们可以使用:UIImagePickerController类来完成。
当然,我们也可以不使用UI的形式来访问iOS设备的相册资源。
那就是使用:ALAssetsLibrary
一、ALAssetsLibrary是什么
可以说,是一个桥梁把。连接了我们应用程序和相册之间的访问。
ALAssetsLibrary提供了我们对iOS设备中的相片、视频的访问。
ALAssetsLibrary被封装在 框架中。所以,我们在使用时,需要引入该框架。
需添加AssetsLibrary.framework
然后引入
然后引入
#import <AssetsLibrary/ALAsset.h>
#import <AssetsLibrary/ALAssetsLibrary.h>
#import <AssetsLibrary/ALAssetsGroup.h>
#import <AssetsLibrary/ALAssetRepresentation.h>
self.assetsLibrary = [[ALAssetsLibrary alloc] init];
dispatch_queue_t dispatchQueue =dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(dispatchQueue, ^(void) {
// 遍历所有相册
[self.assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAll
usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
// 遍历每个相册中的项ALAsset
[group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index,BOOL *stop) { __block BOOL foundThePhoto = NO;
if (foundThePhoto){
*stop = YES;
}
// ALAsset的类型
NSString *assetType = [result valueForProperty:ALAssetPropertyType];
if ([assetType isEqualToString:ALAssetTypePhoto]){
foundThePhoto = YES;
*stop = YES;
ALAssetRepresentation *assetRepresentation =[result defaultRepresentation];
CGFloat imageScale = [assetRepresentation scale];
UIImageOrientation imageOrientation = (UIImageOrientation)[assetRepresentation orientation];
dispatch_async(dispatch_get_main_queue(), ^(void) {
CGImageRef imageReference = [assetRepresentation fullResolutionImage];
// 对找到的图片进行操作
UIImage *image =[[UIImage alloc] initWithCGImage:imageReference scale:imageScale orientation:imageOrientation];
if (image != nil){
//获取到第一张图片
} else {
NSLog(@"Failed to create the image.");
} });
}
}];
}
failureBlock:^(NSError *error) {
NSLog(@"Failed to enumerate the asset groups.");
}]; });
相关文章:
http://blog.csdn.net/kingsley_cxz/article/details/9165951
最新文章
- 使用C#开发数据库应用系统
- spring,mybatis,多数据源配置
- c++学习笔记——聚合类
- 10 ways to be a faster code reviewer--reference
- SQL Function(方法)
- UWP 共享文件——接收者
- 企业级中带你ELK如何实时收集分析Mysql慢查询日志
- C#Windows 服务的安装说明
- java Web工程师面试题集绵
- 无法对含有多个.java(或.class)文档的程序进行编译(或解释)
- SSM框架的配置
- [Selenium] 在Chrome的开发者工具中验证检查XPath/CSS selectors
- 利用Costura.Fody制作绿色单文件程序(C#程序(含多个Dll)合并成一个Exe)
- CAP定理与BASE理论
- (二维数组 亿进制 或 滚动数组) Hat&#39;s Fibonacci hdu1250
- 查找mac下腾讯视频下载地址
- libcurl.dll 7.60.0静态库包含openssl/zlib
- Codeforces Round #380 Div.2 	F - Financiers Game
- IE强制标准模式---标准模式与兼容模式设置
- 【Python爬虫】如何确定自己浏览器的User-Agent信息
热门文章
- C# 怎么显示中文格式的日期、星期几
- HDU 3533 Escape(BFS+预处理)
- Kaggle:Titanic: Machine Learning from Disaster
- ios app应用在显示屏幕上改中文名
- Effective STL 阅读笔记: Item 4 ~ 5: Call empty instead of checking size() against zero.
- GLASNICI 解题报告
- 微信小程序之wepy自动化架构搭建(fly+wepy-plugin-replace)
- DER编码简介
- BNUOJ 52517 Another Server
- UVA12995 Farey Sequence [欧拉函数,欧拉筛]