屏幕,我設置的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