我正在編寫一個應用程序來顯示iphone相機看到的光照條件的統計數據。我每秒都會拍攝一張照片,並在其上進行計算。從iphone上的視頻輸出中獲取靜止圖像?
要拍攝圖像,我使用下面的方法:
-(void) captureNow
{
AVCaptureConnection *videoConnection = nil;
for (AVCaptureConnection *connection in captureManager.stillImageOutput.connections)
{
for (AVCaptureInputPort *port in [connection inputPorts])
{
if ([[port mediaType] isEqual:AVMediaTypeVideo])
{
videoConnection = connection;
break;
}
}
if (videoConnection) { break; }
}
[captureManager.stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error)
{
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
latestImage = [[UIImage alloc] initWithData:imageData];
}];
}
然而,captureStillImageAsynhronously....
方法將導致通過電話,這是不利於我的應用程序中播放的「快門」聲,它會不斷捕捉圖像。
我讀過,它是不可能禁用此音效。相反,我想從手機視頻輸入捕捉幀:
AVCaptureDeviceInput *newVideoInput = [[AVCaptureDeviceInput alloc] initWithDevice:[self backFacingCamera] error:nil];
,並希望把這些變成UIImage
對象。
我該怎麼做到這一點?我不太瞭解AVFoundation的工作原理 - 我下載了一些示例代碼,並將其修改用於我的目的。
這真的很方便,非常感謝。目前,我只是用stock功能來實現我的應用程序的基礎知識,但是我肯定會在之後檢查你的框架,它看起來非常整齊。 – Oliver