سؤال

Using the AVCam sample, I don't see how I can get access tot he image in the AVCamViewController.m file. I want to preview the captured image, but I don't see how I can access this image in the method: - (IBAction)captureStillImage:(id)sender after the line: [[self captureManager] captureStillImage];

I want add a preview programmatically like so:

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

I have tried to find help here on this, but have not been able to. Does any one here have some hints?

هل كانت مفيدة؟

المحلول

AVcam Store the captured image in photo liberary you need to access the last saved image from photo liberary for this you can use this method.You also need to add the AssetsLiberary.framework to use this als add this #include in .h file

   #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);
    }];
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top