文章和说明可在:http://www.codeproject.com/Articles/330177/Yet-another-Web-Camera-control
由于项目限制,我为Linx平板电脑(Windows 10)开发了WPF应用程序,而不是通用Windows应用程序.我使用WebEye库连接到平板电脑上的网络摄像头并用它拍照.当我将平板电脑保持在横向,但是当我将平板电脑保持在纵向模式时,它的工作正常.在纵向模式下,CameraPreview / VideoWindow自动旋转-90度.
>通过Webcamera RenderTransform或LayoutTransform属性旋转视频窗口周围的控件 – 控件旋转,但视频图像不能正确旋转.
>试图旋转WebCamera Content属性中的VideoWindow – 我从GitHub获取了源代码,并设置了可用于访问的VideoWindow.重新构建库并使用它通过其RenderTransform属性来旋转VideoWindow. https://github.com/jacobbo/WebEye/tree/master/WebCameraControl
无论我做什么,相机预览始终是-90度.
该库很简单,它没有很多属性来操纵视频窗口.
web控件在XAML中.
<wpf:WebCameraControl x:Name="webCameraControl" MouseDoubleClick="webCameraControl_MouseDoubleClick" StylusButtonUp="webCameraControl_StylusButtonUp" MouseUp="webCameraControl_MouseUp" TouchUp="webCameraControl_TouchUp" GotMouseCapture="webCameraControl_GotMouseCapture" />
这是我如何初始化WebCamera.当UserControl加载时,它将自动连接到平板电脑上的网络摄像头.请参阅startViewing()函数.
private WebCameraId _cameraID = null; private void UserControl_Loaded(object sender,RoutedEventArgs e) { startViewing(); } private void startViewing() { List<WebCameraId> cams = (List<WebCameraId>)webCameraControl.GetVideoCaptureDevices(); if (cams.Count > 0) { _cameraID = (WebCameraId)cams[0]; webCameraControl.StartCapture(_cameraID); } }
当应用程序在显示屏幕上检测到更改时,我试图强制控件正确旋转.请参阅DisplaySettingsChanged事件.
public ucWebCam() { InitializeComponent(); Microsoft.Win32.SystemEvents.DisplaySettingsChanged += SystemEvents_DisplaySettingsChanged; } private void SystemEvents_DisplaySettingsChanged(object sender,EventArgs e) { try { double angle = 0; if (SystemParameters.PrimaryScreenWidth > SystemParameters.PrimaryScreenHeight) { angle = 0; } else { angle = -90; } webCameraControl.StopCapture(); adjustWebcamAngle(angle); webCameraControl.StartCapture(_cameraID); } catch (Exception ex) { } } private void adjustWebcamAngle(double angle) { try { // IGNORE portrait boolean flag bool portrait = false; if (angle == 90 || angle == 180) { portrait = true; } // TRIED TO SET THE ANGLE OF THE CONTROL TO NO AVAIL RotateTransform rotTransform = new RotateTransform(angle); //rotTransform.Angle = angle; ScaleTransform scaleTransform = new ScaleTransform(); //scaleTransform.ScaleX = (portrait) ? 0 : 1; //scaleTransform.ScaleY = (portrait) ? 0 : 1; TransformGroup tGroup = new TransformGroup(); //tGroup.Children.Add(scaleTransform); tGroup.Children.Add(rotTransform); // ROTATE CAMERA! webCameraControl.RenderTransform = tGroup; } catch (Exception ex) { } }
到目前为止,我只是旋转了WebCam控件,而不是视频图像.
我在亚历山大的文章中看到了没有喜悦的评论:http://www.codeproject.com/Articles/330177/Yet-another-Web-Camera-control
如何正确旋转相机预览?你能告诉我哪里错了吗?
我附上了两张图片来说明我的问题.