私は、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のものがどのように機能しているかについてはあまりわかりません。サンプルコードをダウンロードして、目的に合わせて変更しました。