我创建了一个简单的Xamarin MonoMac Mac应用程序(裸骨1窗口)。我正在尝试将我的网络摄像头预览到应用程序的主窗口。我使用AVFoundation类来访问网络摄像头。
我可以成功连接到mac的网络摄像头,然后网络摄像头灯亮起,但主窗口上没有视频。
我的c#代码
session = new AVCaptureSession () { SessionPreset = AVCaptureSession.PresetMedium };
var captureDevice = AVCaptureDevice.DefaultDeviceWithMediaType (AVMediaType.Video);
var input = AVCaptureDeviceInput.FromDevice (captureDevice);
if (input == null){
Console.WriteLine ("No input - this won't work on the simulator, try a physical device");
}
session.AddInput (input);
AVCaptureVideoPreviewLayer captureVideoPreviewLayer = new AVCaptureVideoPreviewLayer (session);
**//----> preview layer onto Window here ?!**
session.StartRunning ();
答案 0 :(得分:4)
这解决了它 - 希望它会帮助某人......
AVCaptureVideoPreviewLayer captureVideoPreviewLayer = AVCaptureVideoPreviewLayer.FromSession (session);
this.Window.ContentView.Layer=captureVideoPreviewLayer;
this.Window.ContentView.WantsLayer=true;
session.StartRunning ();