2

使用 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];

我试图在这里寻求帮助,但一直未能。这里有人有一些提示吗?

4

1 回答 1

6

AVcam 将捕获的图像存储在照片库中,您需要访问照片库中最后保存的图像,您可以使用此方法。您还需要添加 AssetsLiberary.framework 以使用此 als 添加此#include 在 .h 文件中

   #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);
    }];
}
于 2012-09-10T09:18:10.683 回答