以编程方式缩放 AudioVideoCaptureDevice? [英] Programmatically zooming the AudioVideoCaptureDevice?

查看:25
本文介绍了以编程方式缩放 AudioVideoCaptureDevice?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Anybody know how to programmatically zoom the AudioVideoCaptureDevice in Windows Phone 8?

我正在使用 AudioVideoCaptureDevice(是的,我想要那个特定的设备,以便我可以控制 VideoTorchMode 属性).不过,我终生无法弄清楚变焦.我正在使用映射到 AudioVideoCaptureDevice 的 VideoBrush 绘制画布.我想实现双指缩放甚至是一个简单的 +/- 按钮来缩放相机.

I am using AudioVideoCaptureDevice (and yes, I want that specific device so I can control the VideoTorchMode property). I can't for the life of me figure out the zooming though. I am painting a Canvas using a VideoBrush mapped to the AudioVideoCaptureDevice. I'd like to implement Pinch-Zoom or even a simple +/- button to Zoom the camera.

我错过了什么?

推荐答案

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

I'm not familiar with any API in WP8 that would allow you to programmetically set the zoom on a PhotoCaptureDevice/AudioVideoCaptureDevice. My theory is that you can do it manually by implementing your own Pinch-to-zoom functionality and making sure that region is focused.

有关如何使用 WP8 相机 API 聚焦区域的信息,请参阅诺基亚的Camera Explorer.您可以在此架构指南中找到您正在寻找的核心内容在点按对焦"下.

For information on how to Focus on a region using WP8 Camera APIs see Nokia's Camera Explorer. The core of what you're looking for can be found on this architectural guide under "tap-to-focus".

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 中的双指缩放功能

Here's how to implement your own pinch-to-zoom functionality in WP8 @ Pinch To Zoom functionality in windows phone 8

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

One thing I'd add to the pinch-to-zoom code sample in your case is a Clip specification on a parent control to make sure you're not accidentally rendering images tens or hundreds of times bigger then the screen and killing your app's performance.

这篇关于以编程方式缩放 AudioVideoCaptureDevice?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆