屏幕,我设置的AVCaptureSession
预设PhotoPreset捕捉图像预览像与AVFoundation
self.session.sessionPreset = AVCaptureSessionPresetPhoto;
,然后添加一个新层,进入我的看法与
AVCaptureVideoPreviewLayer *previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.session];
[previewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
CALayer *rootLayer = [self.view layer];
[rootLayer setMasksToBounds:YES];
[previewLayer setFrame:[rootLayer bounds]];
[rootLayer addSublayer:previewLayer];
到目前为止好,但是上当我想要捕捉图像时,我使用下面的代码
AVCaptureConnection *videoConnection = [self.stillImageOutput connectionWithMediaType:AVMediaTypeVideo];
[self.stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error)
{
[self.session stopRunning];
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
UIImage *image = [[UIImage alloc] initWithData:imageData ];
self.imageView.image = image; //IMAGEVIEW IS WITH THE BOUNDS OF SELF.VIEW
image = nil;
}];
捕获图像是f然而,与在屏幕上显示的AVCaptureVideoPreviewLayer
相比,所捕获的图像是不同的。我真正想要做的就是展示抓取图案,就像出现在AVCapturePreviewLayer
图层上一样。我怎样才能做到这一点?我应该如何调整和裁剪拍摄的图像相对于self.view
的界限?
我有同样的问题,你有没有找到解决方案或可能导致我们找到解决方案的东西? (: 谢谢。 – 2013-05-20 12:04:01
WWDC 2011 Session 419解决了我所有的问题,他们也有示例代码,以解决您的问题:) – kkocabiyik 2013-05-27 22:06:22
@kkocabiyik,虽然我很欣赏参考,但如果您可以详细说明你在这里解决你自己的问题。人们将继续通过谷歌或搜索找到你未答复的问题,并发表评论说,一小时长的视频解决了你的问题并不完全帮助其他人。至少时间戳会有帮助。 – bradleygriffith 2013-08-05 19:06:45