在View Controller中传递UIImage和Display

时间:2013-11-06 22:02:53

标签: ios objective-c uiimage

您好我正在一个名为CaptureManager的NSObject中保存图像。在.h中我设置了UIImage属性:

@property (nonatomic,strong) UIImage *captureImage;

然后在.m中设置图像

       - (void) captureStillImage
{
    AVCaptureConnection *stillImageConnection = [[self stillImageOutput] connectionWithMediaType:AVMediaTypeVideo];

    [[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:stillImageConnection
                                                         completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {

                                                             if (imageDataSampleBuffer != NULL) {
                                                                 NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];

                                                                 captureImage = [[UIImage alloc] initWithData:imageData];

                                                                 [[NSNotificationCenter defaultCenter] postNotificationName: @"photoTaken" object:nil userInfo:nil];
                                                             }

                                                             if ([[self delegate] respondsToSelector:@selector(captureManagerStillImageCaptured:)]) {
                                                                 [[self delegate] captureManagerStillImageCaptured:self];
                                                             }
                                                         }];
}

现在在我的ViewController中,我试图像这样显示图像:

CaptureManager *captureManager = [[CaptureManager alloc] init];

    UIImage *captureBackgroundImage = captureManager.captureImage;

    UIImageView *captureImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
    [captureImageView setImage:captureBackgroundImage];
    [self.view addSubview:captureImageView];
    [self.view bringSubviewToFront:captureImageView];

我做的一切都正确吗?我有captureImage设置的问题吗?可能是在captureStillImage方法中,完成处理程序弄乱了吗?屏幕上没有显示任何内容。任何帮助都会非常感激!

0 个答案:

没有答案