我正试着从iphone相机卷上得到最后一张照片。我使用以下代码:
UIImage* __block image = [[UIImage alloc] init];
ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup* group, BOOL* stop) {
[group setAssetsFilter:[ALAssetsFilter allPhotos]];
if ([group numberOfAssets] > 0) {
[group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:[group numberOfAssets]-1] options:NSEnumerationConcurrent usingBlock:^(ALAsset* alAsset, NSUInteger index, BOOL* innerStop) {
if (alAsset) {
ALAssetRepresentation* rawImage = [alAsset defaultRepresentation];
image = [UIImage imageWithCGImage:[rawImage fullScreenImage]];
[self doTheJobWithImage:image];
// Inside doTheJobWithImage: a segue is also performed at the end
}
}];
}
} failureBlock:^(NSError* error) {
NSLog(@"Error: %@", [error localizedDescription]);
}];
它可以工作,但有缺陷(我使用仪器和僵尸来调试它):
我正在使用xcode 4.6、ios 6和ARC。提前谢谢。
发布于 2013-02-17 21:35:19
几个小时后,我发现这里的代码没有什么问题。这是正确的代码来提取相机卷中的最后一张图片(如果有人需要的话)。问题是在doTheJobWithImage:,我解决了它替换
[self doTheJobWithImage:image];
并将结果图像存储在其他地方,然后执行doTheJobWithImage:在完成图片枚举之后。说这些只是为了防止别人感兴趣。
https://stackoverflow.com/questions/14920408
复制相似问题