有人知道如何以编程方式缩放Windows Phone 8中的AudioVideoCaptureDevice吗?
我正在使用AudioVideoCaptureDevice(是的,我想要那个特定的设备,所以我可以控制VideoTorchMode属性)。我不能为我的生活找出变焦但是。我正在使用映射到AudioVideoCaptureDevice的VideoBrush绘制Canvas。我想实现Pinch-Zoom甚至是简单的+/-按钮来缩放相机。
我错过了什么?
答案 0 :(得分:2)
我不熟悉WP8中的任何API,它允许您在PhotoCaptureDevice / AudioVideoCaptureDevice上程序设置缩放。我的理论是,您可以通过实现自己的缩放到缩放功能并确保该区域集中来手动完成。
有关如何使用WP8 Camera API关注区域的信息,请参阅诺基亚的Camera Explorer。您正在寻找的核心可以在this architectural guide下的“点击关注”下找到。
private async void videoCanvas_Tap(object sender, GestureEventArgs e)
{
System.Windows.Point uiTapPoint = e.GetPosition(VideoCanvas);
if (_focusSemaphore.WaitOne(0))
{
// Get tap coordinates as a foundation point
Windows.Foundation.Point tapPoint = new Windows.Foundation.Point(uiTapPoint.X, uiTapPoint.Y);
double xRatio = VideoCanvas.ActualWidth / _dataContext.Device.PreviewResolution.Width;
double yRatio = VideoCanvas.ActualHeight / _dataContext.Device.PreviewResolution.Height;
// adjust to center focus on the tap point
Windows.Foundation.Point displayOrigin = new Windows.Foundation.Point(
tapPoint.X - _focusRegionSize.Width / 2,
tapPoint.Y - _focusRegionSize.Height / 2);
// adjust for resolution difference between preview image and the canvas
Windows.Foundation.Point viewFinderOrigin = new Windows.Foundation.Point(displayOrigin.X / xRatio, displayOrigin.Y / yRatio);
Windows.Foundation.Rect focusrect = new Windows.Foundation.Rect(viewFinderOrigin, _focusRegionSize);
// clip to preview resolution
Windows.Foundation.Rect viewPortRect = new Windows.Foundation.Rect(0, 0, _dataContext.Device.PreviewResolution.Width, _dataContext.Device.PreviewResolution.Height);
focusrect.Intersect(viewPortRect);
_dataContext.Device.FocusRegion = focusrect;
// show a focus indicator
FocusIndicator.SetValue(Shape.StrokeProperty, _notFocusedBrush);
FocusIndicator.SetValue(Canvas.LeftProperty, uiTapPoint.X - _focusRegionSize.Width / 2);
FocusIndicator.SetValue(Canvas.TopProperty, uiTapPoint.Y - _focusRegionSize.Height / 2);
FocusIndicator.SetValue(Canvas.VisibilityProperty, Visibility.Visible);
CameraFocusStatus status = await _dataContext.Device.FocusAsync();
if (status == CameraFocusStatus.Locked)
{
FocusIndicator.SetValue(Shape.StrokeProperty, _focusedBrush);
_manuallyFocused = true;
_dataContext.Device.SetProperty(KnownCameraPhotoProperties.LockedAutoFocusParameters,
AutoFocusParameters.Exposure & AutoFocusParameters.Focus & AutoFocusParameters.WhiteBalance);
}
else
{
_manuallyFocused = false;
_dataContext.Device.SetProperty(KnownCameraPhotoProperties.LockedAutoFocusParameters, AutoFocusParameters.None);
}
_focusSemaphore.Release();
}
}
以下是如何在WP8 @ Pinch To Zoom functionality in windows phone 8
中实现自己的缩放缩放功能我要添加到您的案例中的缩放到缩放代码示例的一件事是父控件上的 Clip 规范,以确保您不会意外渲染图像比屏幕大几十倍或几百倍,并且会破坏应用程序的性能。