gpt4 book ai didi

iphone - 获取 iPhone 相机拍摄的最后一张图像

转载 作者:行者123 更新时间:2023-12-03 20:25:51 24 4
gpt4 key购买 nike

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

最佳答案

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

类似这样的东西应该可以将最后一张图像作为缩略图:

- (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);
}];
}

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

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

关于iphone - 获取 iPhone 相机拍摄的最后一张图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7006292/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com