- Alassetslibrary class
- Alassetsgroup
- Alasset class
As the blog migrated to Www.coderyi.com, the article see http://www.coderyi.com/archives/424
There are several classes under the framework, alassetslibrary,alassetsgroup,alasset,alassetsfilter,alassetrepresentation.
Alassetslibrary class
Alassetslibrary class can be used to view album list, add albums, save pictures to albums and other functions.
For example, the Enumerategroupswithtypes method lists all albums.
Alassetsgroup
Alassetsgroup is the class of the album, you can view the values of different properties by Valueforproperty method, such as: Alassetsgrouppropertyname, album name.
Alassetsgroup class has several methods, Posterimage method is the cover picture of the album, Numberofassets method to get the number of pictures and videos of the album, you can use the Enumerateassetsusingblock method to enumerate all the photos.
Alassetsgroup can filter photos or videos using Setassetsfilter: (Alassetsfilter *) filters.
The first is to get all the albums, using the Alassetslibrary instance method to get the Alassetsgroup class array.
?
123456789101112131415 |
ALAssetsLibrary *assetsLibrary;
NSMutableArray *groupArray;
assetsLibrary = [[ALAssetsLibrary alloc] init];
groupArray=[[NSMutableArray alloc] initWithCapacity:1];
[assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group,
BOOL
*stop) {
if
(group) {
[groupArray addObject:group];
// 通过这个可以知道相册的名字,从而也可以知道安装的部分应用
//例如 Name:柚子相机, Type:Album, Assets count:1
NSLog(@
"%@"
,group);
}
} failureBlock:^(NSError *error) {
NSLog(@
"Group not found!\n"
);
}];
|
Alasset class
The Alasset class can also view the values of different properties through the Valueforproperty method, such as: Alassetpropertytype,asset type, three Alassettypephoto, Alassettypevideo or Alassettypeunknown.
In addition, this method can be used to obtain alassetpropertylocation (photo location), alassetpropertyduration (video time), alassetpropertydate (photo shooting date) and so on.
The thumbnail method is to get the photo.
According to the album to get all the pictures under the album, through the Alassetsgroup instance method to get the Alasset class array.
?
12345678 |
[_group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index,
BOOL
*stop) {
if
(result) {
[imageArray addObject:result];
NSLog(@
"%@"
,result);
iv.image=[UIImage imageWithCGImage: result.thumbnail];
NSString *type=[result valueForProperty:ALAssetPropertyType];
}
}];
|
Alassetrepresentation class
The Alasset class has a defaultrepresentation method, and the return value is the Alassetrepresentation class that is used to obtain detailed resource information for the resource picture.
Such as
?
12345678910111213141516171819202122232425 |
//
//获取资源图片的详细资源信息
ALAssetRepresentation* representation = [asset defaultRepresentation];
//获取资源图片的长宽
CGSize dimension = [representation dimensions];
//获取资源图片的高清图
[representation fullResolutionImage];
//获取资源图片的全屏图
[representation fullScreenImage];
//获取资源图片的名字
NSString* filename = [representation filename];
NSLog(@
"filename:%@"
,filename);
//缩放倍数
[representation scale];
//图片资源容量大小
[representation size];
//图片资源原数据
[representation metadata];
//旋转方向
[representation orientation];
//资源图片url地址,该地址和ALAsset通过ALAssetPropertyAssetURL获取的url地址是一样的
NSURL* url = [representation url];
NSLog(@
"url:%@"
,url);
//资源图片uti,唯一标示符
NSLog(@
"uti:%@"
,[representation UTI]);
|
iOS assetslibrary framework to access all photos