概述
在调用系统相册时,想提取系统相册最后一张图的缩略图作为相册入口的图,代码如下:
#pragma mark - 获取相册最后一张照片
- (void)GetLastestPhoto
{
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
__block UIImage *imagelast;
// Enumerate just the photos and videos group by using ALAssetsGroupSavedPhotos.
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
// Within the group enumeration block, filter to enumerate just photos.
[group setAssetsFilter:[ALAssetsFilter allPhotos]];
// Chooses the photo at the last index
[group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop) {
// The end of the enumeration is signaled by asset == nil.
if (alAsset) {
ALAssetRepresentation *representation = [alAsset defaultRepresentation];
UIImage *latestPhoto = [UIImage imageWithCGImage:[representation fullScreenImage]];
imagelast = latestPhoto;
// Stop the enumerations
*stop = YES; *innerStop = YES;
self.albumImageView.image = imagelast;
// Do something interesting with the AV asset.
//[self sendTweet:latestPhoto];
}
}];
} failureBlock: ^(NSError *error) {
// Typically you should handle an error more gracefully than this.
NSLog(@"No groups");
}];
}
//相册入口
self.albumImageView = [[UIImageView alloc] init];
self.albumImageView.backgroundColor = [UIColor clearColor];
self.albumImageView.userInteractionEnabled = YES;
self.albumImageView.frame = DF_FRAME(DF_WIDTH-5-44, DF_BOTTOM_MENU_H/2-44/2, 44, 44);
UITapGestureRecognizer *singleTap =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(showalbum:)];
[self.albumImageView addGestureRecognizer:singleTap];
[self GetLastestPhoto];
// 相册缩略图初始化
[view addSubview:self.albumImageView];
效果图:
最后
以上就是背后星月为你收集整理的获取相册最后一张图(作为相册的入口)的全部内容,希望文章能够帮你解决获取相册最后一张图(作为相册的入口)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复