1

我正在尝试在相机应用程序中提供缩放功能,为此我正在使用 MediaCapture 类,MediaCapture 的所有其他功能都可以正常工作,除了缩放,我正在使用以下代码来实现缩放:

private void zoomSlider_ValueChanged(object sender, Windows.UI.Xaml.Controls.Primitives.RangeBaseValueChangedEventArgs e)
{
    m_mediaCaptureMgr.VideoDeviceController.Zoom.TrySetValue(zoomSlider.Value);
}

但它不起作用请告诉我该怎么做?

编辑:代码格式更正

4

2 回答 2

3

你也可以像这样在 XAML 中缩放相机视图

<CaptureElement x:Name="previewElement1" Width="1366" Height="672">
                <CaptureElement.RenderTransform>
                    <ScaleTransform  x:Name="zoom"/>
                </CaptureElement.RenderTransform>
                </CaptureElement>

<Slider  Width="30" Height="300" Name="zoomSlider" ValueChanged="zoomSlider_ValueChanged_1" />

在 C# 中

private void zoomSlider_ValueChanged_1(object sender, Windows.UI.Xaml.Controls.Primitives.RangeBaseValueChangedEventArgs e)
{
    try
    {
        zoom.ScaleX = zoomSlider.Value;
        zoom.ScaleY = zoomSlider.Value;
        zoom.CenterX = 683;
        zoom.CenterY = 384;
    }
    catch (Exception)
    {
    }
}
于 2012-07-21T06:02:34.680 回答
2

<ScaleTransform>不修改相机的变焦。它只是放大图像,因此您会看到相同的图像更加像素化。

相机的变焦是由ZoomControl类控制的。它位于MediaCapture课堂内。

示例:Slider元素更改相机的缩放。

<CaptureElement x:Name="captureElement"
                Stretch="UniformToFill" />

<Slider x:Name="sliderZoom"
        Width="250"
        ValueChanged="sliderZoom_ValueChanged"/>

的配置Slider

MediaCapture _mediaCapture;

// Initialization of the MediaCapture ...

if(this._mediaCapture.VideoDeviceController.ZoomControl.Supported)
{
    sliderZoom.Minimum = this._mediaCapture.VideoDeviceController.ZoomControl.Min;
    sliderZoom.Maximum = this._mediaCapture.VideoDeviceController.ZoomControl.Max;
    sliderZoom.StepFrequency = this._mediaCapture.VideoDeviceController.ZoomControl.Step;
}

Slider当改变其值时修改相机的缩放:

private void sliderZoom_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
{
    if(this._mediaCapture.VideoDeviceController.ZoomControl.Supported)
    {
        this._mediaCapture.VideoDeviceController.ZoomControl.Value = (float)e.NewValue;
    }
}

如果StepFrequency不等于ZoomControl.Step尝试修改缩放时将显示此错误:

An exception of type 'System.ArgumentException' occurred in ....exe but was not handled in user code
WinRT information: Zoom factor
Additional information: The parameter is incorrect.
于 2014-12-30T21:09:29.170 回答