1

有人知道如何在 Windows Phone 8 中以编程方式缩放 AudioVideoCaptureDevice 吗?

我正在使用 AudioVideoCaptureDevice(是的,我想要那个特定的设备,这样我就可以控制 VideoTorchMode 属性)。我不能为我的生活弄清楚缩放虽然。我正在使用映射到 AudioVideoCaptureDevice 的 VideoBrush 绘制画布。我想实现 Pinch-Zoom 甚至是一个简单的 +/- 按钮来缩放相机。

我错过了什么?

4

1 回答 1

2

我不熟悉 WP8 中允许您以编程方式在 PhotoCaptureDevice/AudioVideoCaptureDevice 上设置缩放的任何 API。我的理论是,您可以通过实现自己的捏合缩放功能并确保该区域被聚焦来手动完成。

有关如何使用 WP8 相机 API 专注于某个区域的信息,请参阅诺基亚的相机资源管理器。您正在寻找的核心内容可以在此架构指南中的“点击聚焦”下找到。

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 中实现您自己的捏合缩放功能@Windows Phone 8 中的捏合缩放功能

在您的情况下,我要添加到捏合缩放代码示例中的一件事是父控件上的Clip规范,以确保您不会意外渲染比屏幕大数十或数百倍的图像并破坏您的应用程序的性能.

于 2013-01-24T01:29:38.260 回答