QTCaptureLayerがすごく簡単な件について
公開日:
:
最終更新日:2014/01/31
cocoa
記事内に広告を含む場合があります。記事内で紹介する商品を購入することで、当サイトに売り上げの一部が還元されることがあります。
Webカメラからの動画をリアルタイムで流しつつ、カーソルキーで選択できるメニューをオーバーラップ表示。
Webカメラに関するコードは以下の通り。簡単すぎる。
//Create the capture session
mCaptureSession = [[QTCaptureSession alloc] init];
//Connect inputs and outputs to the session
BOOL success = NO;
NSError *error;
// Find a video device
QTCaptureDevice *device = [QTCaptureDevice defaultInputDeviceWithMediaType:QTMediaTypeVideo];
if (device) {
success = [device open:&error];
if (!success) {
// Handle error
}
}
// Add the video device to the session as device input
mCaptureDeviceInput = [[QTCaptureDeviceInput alloc] initWithDevice:device];
success = [mCaptureSession addInput:mCaptureDeviceInput error:&error];
if (!success) {
// Handle error
}
QTCaptureLayer *rootLayer;
rootLayer = [[QTCaptureLayer alloc] initWithSession:mCaptureSession];
// Start the capture session running
[mCaptureSession startRunning];
[self setLayer:rootLayer];