IOS,AVCam,如何预览拍摄的图像?

sAg*_*aga 2 preview uiimageview ios avcapture

使用AVCam示例,我看不到如何访问AVCamViewController.m文件中的图像.我想预览捕获的图像,但我不知道如何在方法中访问此图像:- (IBAction)captureStillImage:(id)sender在行之后:[[self captureManager] captureStillImage];

我想以编程方式添加预览,如下所示:

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320/5, 480/5)];
    [imageView setImage:[captureManager image]];
    [self.view addSubview:imageView];
    [imageView release];
Run Code Online (Sandbox Code Playgroud)

我试图在这里找到帮助,但一直没能.这里有人有一些提示吗?

小智 6

AVcam将捕获的图像存储在照片中,您需要从照片版权中访问上次保存的图像,这样您就可以使用此方法.您还需要添加AssetsLiberary.framework以使用此als在.h文件中添加此#include

   #include <AssetsLibrary/AssetsLibrary.h>

    @interface PhotoViewController :  UIViewController<UIImagePickerControllerDelegate,UIPopoverControllerDelegate>{

        ALAssetsLibrary *assetsLibrary;
    }
    - (void)viewDidLoad
    {
        assetsLibrary = [[ALAssetsLibrary alloc] init];
        [self updateLastPhotoThumbnail];

      }
- (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) {
                    YouImageView.image = thumbnail;
                    *stop = YES;
                }
            }];
        }
    } failureBlock:^(NSError *error) {
        NSLog(@"error: %@", error);
    }];
}
Run Code Online (Sandbox Code Playgroud)