iOS - 获取手机中所有图片
1 #import <AssetsLibrary/AssetsLibrary.h> /**
6 * ALAssetsLibrary.h 代表资源库(所有的视频,照片)
7 ALAssetsGroup.h 代表资源库中的相册
8 ALAsset.h 代表相册中一个视频或者一张照片
9 ALAssetRepresentation.h 代表一个资源的描述,可以获取到原始图片
10 */ @interface ViewController () @property (weak, nonatomic) IBOutlet UICollectionView *collectionView; @property (nonatomic,strong)NSMutableArray *array;
@end @implementation ViewController{ ALAssetsLibrary *library; } - (void)viewDidLoad {
[super viewDidLoad]; //创建可变数组,存储资源文件
_array = [NSMutableArray array]; //创建资源库,用于访问相册资源
library = [[ALAssetsLibrary alloc] init]; //遍历资源库中所有的相册,有多少个相册,usingBlock会调用多少次
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) { //如果存在相册,再遍历
if (group) { //遍历相册中所有的资源(照片,视频)
[group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) { /*
44 资源的索引
45 if (index == 2) {
46
47 //停止遍历
48 *stop = YES;
49 }
50 */ if (result) {
//将资源存储到数组中
[_array addObject:result];
} }];
} //刷新_collectionView reloadData;
[_collectionView reloadData]; } failureBlock:^(NSError *error) { NSLog(@"访问失败");
}]; } #pragma mark -UICollectionViewDelegate //行的个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return _array.count; } //创建UICollectionViewCell
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { //如果单元格是在故事版中画出来的,不需要注册,需要在单元格中指定标识符
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath]; //取得图片视图
UIImageView *imgView = (UIImageView *)[cell.contentView viewWithTag:]; //取出对应的资源数据
ALAsset *result =_array[indexPath.row]; //获取到缩略图
CGImageRef cimg = [result thumbnail]; //转换为UIImage
UIImage *img = [UIImage imageWithCGImage:cimg]; //显示图片
imgView.image = img; /**
102 * 获取到原始图片
103 ALAssetRepresentation *presentation = [result defaultRepresentation];
104
105 CGImageRef resolutionImg = [presentation fullResolutionImage];
106 */ return cell; } //单元格大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{ return CGSizeMake(, );
iOS - 获取手机中所有图片的更多相关文章
- 获取HTML中所有图片的 URL
/// <summary> /// 获取HTML中所有图片的 URL /// </summary> /// <param name="strHtml" ...
- ios 获取手机信息(UIDevice、NSBundle、NSLocale)
iOS的SDK中提供了UIDevice.NSBundle,NSLocale. UIDevice UIDevice提供了多种属性.类函数及状态通知,帮助我们全方位了解设备状况. 从检測电池 ...
- iOS获取手机相关信息
iOS具体的设备型号: #include <sys/types.h> #include <sys/sysctl.h> - (void)test { //手机型号. size_t ...
- 【Android】获取手机中已安装apk文件信息(PackageInfo、ResolveInfo)(应用图片、应用名、包名等)
众所周知,通过PackageManager可以获取手机端已安装的apk文件的信息,具体代码如下 PackageManager packageManager = this.getPackageManag ...
- ios 获取手机相关的信息
获取手机信息 应用程序的名称和版本号等信息都保存在mainBundle的一个字典中,用下面代码可以取出来 //获取版本号 NSDictionary *infoDict = [[NSBundl ...
- Android_(传感器)获取手机中的传感器
传感器是一种检测装置,能够感受被测量的信息,并能将检测和感受到的信息按一定规律变换成电信号或其它所需形式的信息输出 Android操作系统中内置了很多的传感器(物理装置),能够探测.感受外界的信号.物 ...
- iOS获取手机型号,类似iphone 7这种 含swift和OC
获取手机设备信息,如name.model.version等,但如果想获取具体的手机型号,如iphone5.5s这种,就需要如下这种 swift: func phonetype () -> Str ...
- IOS 获取通讯录中信息
获取通讯录中信息 一. 我们设置一个ABAddressBookRef类型的属性addressBook. 二. 要获得通讯录中的信息,我们需要获取访问通讯录的权限. 在运行下面的获取权限的方法的时候,系 ...
- iOS获取手机型号,Swift获取手机型号(类似iphone 7这种,检测机型具体型号)
获取手机设备信息,如name.model.version等, 但如果想获取具体的手机型号,如iphone5.5s这种,就需要如下这种(含Swift和OC两种写法) Swift建议添加到extensio ...
随机推荐
- fcntl 获取文件状态标志
int fcntl(int fd,int cmd,...) 函数fcntl提供了非常丰富的功能.主要依赖于cmd的各种参数: 复制已有的文件描述符 F_DUPFD,F_DUPFD_CLOEXEC 获取 ...
- 探索 OpenStack 之(9):深入块存储服务Cinder (功能篇)
继研究了Neutron之后,继续Nova的外围研究之旅.本站是研究块存储服务Cinder. 0.验证环境 环境包括: 1.一个controller节点,运行nova-api, nova-schedul ...
- Android的面孔_Actiyity
一.什么是Activity? 简单的说:Activity就是布满整个窗口或者悬浮于其他窗口上的交互界面.在一个应用程序中通常由多个Activity构成,都会在Manifest.xml中指定一个主的Ac ...
- EZ GUI Button和Checkbox创建
第一次接触EZ GUI,记录学习过程 准备工作 导入资源 导入 EZ GUI 1.0795.unitypackage 和 SpriteManager2 v1.92.unitypackage EZGUI ...
- NGUI Sprite Type(Simple、Sliced、Tiled、Filed、Advanced)
官方文档:http://www.tasharen.com/forum/index.php?topic=6704.0 Sprite Type 下面是UISprite的Type截图,每一种Type都有不同 ...
- 书籍推荐 《移动Web手册》 奇舞团
书籍推荐 <移动Web手册> 奇舞团
- RecyclerView (一) 基础知识
RecyclerView是什么? RecyclerView是一种新的视图组,目标是为任何基于适配器的视图提供相似的渲染方式.它被作为ListView和GridView控件的继承者,在最新的suppor ...
- python算法:rangeBitwiseAnd(连续整数的与)
def rangeBitwiseAnd(self, m, n): i = 0 while m != n: m >>= 1 n >>= 1 i += 1 return n < ...
- 分享JS代码(转)
var imgUrl = 'http://xxx/share_ico.png'; // 分享后展示的一张图片 var lineLink = 'http://xxx'; // 点击分享后跳转的页面地址 ...
- [资料收集]MySQL在线DDL工具pt-online-schema-change
MySQL在线DDL工具pt-online-schema-change pt-online-schema-change使用说明(未完待续) 官网