2012-08-15 65 views
2

使用AVCam示例,我沒有看到如何在AVCamViewController.m文件中訪問他的圖像。我要預覽所拍攝的圖像,但我不明白我怎麼可以在方法訪問該圖像:[[self captureManager] captureStillImage];IOS,AVCam,我如何預覽拍攝的圖像?

我想以編程方式添加一個預覽,像這樣:

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

行後- (IBAction)captureStillImage:(id)sender我試圖在這裏找到幫助,但一直未能。這裏有任何人有一些提示嗎?

回答

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