获取通过iPhone相机捕获的最后一个图像 [英] Fetching the last image captured through iPhone camera

查看:114
本文介绍了获取通过iPhone相机捕获的最后一个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图以编程方式获取iPhone中的相机捕获的图片。现在,问题是我使用AVCaptureInput和其他AVFoundation标头和访问iPhone的摄像头,而不是简单的UIImagePickerViewController因为,该程序需要一个小视图内的主视图显示摄像头镜头。所以现在,问题是我需要获取我捕获的最后一个图像。它被存储在库中的相机卷文件夹中。我需要显示它作为最后捕获的图​​像的预览 - 正如iPhone的相机一样。

I am trying fetch the picture which is captured by the camera in the iPhone, programmatically. Now, the issue is I am using AVCaptureInput, and other AVFoundation headers and accessing the camera of iPhone instead of simple UIImagePickerViewController because, the program needs a small view inside the main view showing the camera footage. So Now, the issue is I need to fetch the last image I captured. It is being stored in camera roll folder inside library. I need to show it as a preview of last image captured - exactly as how the iPhone's camera does.

推荐答案

您可以使用 AssetsLibrary 框架访问相机中的照片

You can use the AssetsLibrary framework to access photos in the camera roll.

这样可以获得最后一张图片作为缩略图:

Something like this should work for getting the last image as a thumbnail:

- (void)updateLastPhotoThumbnail
{
    [assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
        NSInteger numberOfAssets = [group numberOfAssets];
        if (numberOfAssets > 0) {
            NSInteger lastIndex = numberOfAssets - 1;
            [group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:lastIndex] options:0 usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
                UIImage *thumbnail = [UIImage imageWithCGImage:[result thumbnail]];
                if (thumbnail && thumbnail.size.width > 0) {
                    photoThumbnailView.image = thumbnail;
                    *stop = YES;
                }
            }];
        }
    } failureBlock:^(NSError *error) {
        NSLog(@"error: %@", error);
    }];
}

这假设您已将assetsLibrary初始化为实例变量。然后,您还可以观察在库更改时发布的通知(也可能在您的应用外发生):

This is assuming that you have assetsLibrary initialized as an instance variable. You can then also observe the notification that is posted when the library changes (could also happen outside of your app):

assetsLibrary = [[ALAssetsLibrary alloc] init];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateLastPhotoThumbnail) name:ALAssetsLibraryChangedNotification object:nil];

这篇关于获取通过iPhone相机捕获的最后一个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆