无法在宏碁平板电脑的xaml应用程序中获得最大分辨率的相机

本文关键字:相机 分辨率 应用程序 宏碁 平板电脑 xaml | 更新日期: 2023-09-27 18:15:23

这段代码是为了获得最佳(最大)分辨率的摄像头,然后拍照,但它只拍摄VGA照片,而摄像头有800万像素的分辨率。请纠正我这个代码有什么问题。由于

<Page
x:Class="win8appbycrs.BlankPage2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:win8appbycrs"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
    <Image x:Name="image" HorizontalAlignment="Left" Height="424" Margin="254,45,0,0" VerticalAlignment="Top" Width="619"/>
    <Button Content="Set" HorizontalAlignment="Left" Margin="978,293,0,0" VerticalAlignment="Top" Click="Button_Click"/>
    <CaptureElement x:Name="ce" HorizontalAlignment="Left" Height="268" Margin="97,490,0,0" VerticalAlignment="Top" Width="421" Stretch="Fill"/>
    <ComboBox x:Name="ComboBox1" HorizontalAlignment="Left" Margin="659,474,0,0" VerticalAlignment="Top" Width="120"/>
    <Button Content="Capture" HorizontalAlignment="Left" Margin="840,499,0,0" VerticalAlignment="Top" Click="Button_Click_1"/>
    <Image x:Name="Img" HorizontalAlignment="Left" Height="225" Margin="254,133,0,0" VerticalAlignment="Top" Width="356"/>
</Grid>

c#代码:

 public BlankPage2()
    {
        InitializeComponent();
        mediaCaptureMgr = new MediaCapture();
        StartPreview();
    }
    /// <summary>
    /// Invoked when this page is about to be displayed in a Frame.
    /// </summary>
    /// <param name="e">Event data that describes how this page was reached.  The Parameter
    /// property is typically used to configure the page.</param>
    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
    }

    private async void Button_Click(object sender, RoutedEventArgs e)
    {
        int max_res = 0;
        int selected = 0;
        string sCameraName;
        var interfaces = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(Windows.Devices.Enumeration.DeviceClass.VideoCapture);
        foreach (DeviceInformation deviceInterface in interfaces)
        {
            sCameraName = deviceInterface.Name.ToString();
            MediaCaptureInitializationSettings captureInitSettings = new Windows.Media.Capture.MediaCaptureInitializationSettings();
            captureInitSettings.VideoDeviceId = deviceInterface.Id;
            captureInitSettings.PhotoCaptureSource = PhotoCaptureSource.VideoPreview;

            //enumerate each camera for supported configurations
            MediaCapture mediaCaptureMgr = new Windows.Media.Capture.MediaCapture();
            await mediaCaptureMgr.InitializeAsync(captureInitSettings);
            //System.Collections.Generic.IReadOnlyList<IMediaEncodingProperties> res = mediaCaptureMgr.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoRecord);
res = mediaCaptureMgr.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview);

            //if no settings available, bail
            if (res.Count < 1) return;
            //list the number of setting combinations for the device
            string sCount = sCameraName + ": " + res.Count.ToString();
            //            ComboBox1.Items.Add(sCount);
            //list the different format settings
            for (int i = 0; i < res.Count; i++)
            {
                VideoEncodingProperties vp = (VideoEncodingProperties)res[i];
                if (vp.Width * vp.Height > max_res)
                {
                    resolutionMax=vp;
                    max_res = (int)vp.Width;
                    selected  = i;

                }
            }

        }
        setres(selected);
    }
    async void StartPreview()
    {
        try
        {
            await mediaCaptureMgr.InitializeAsync();
            ce.Source = mediaCaptureMgr;
            await mediaCaptureMgr.StartPreviewAsync();
        }
        catch (Exception ex)
        {
            mediaCaptureMgr = null;
            GC.Collect();
        }
    }
    private async void setres(int maxres)
    {
        await mediaCaptureMgr.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview  , res[maxres]);
    }
    private async void Button_Click_1(object sender, RoutedEventArgs e)
    {
        var captureSettings = new ImageEncodingProperties();
        captureSettings.Height = resolutionMax.Height;
        captureSettings.Width = resolutionMax.Width;
        captureSettings.Subtype = "Jpeg";
        // Requires documentsLibrary capability
        var folder = ApplicationData.Current.RoamingFolder;
                           var folder1 = KnownFolders.PicturesLibrary;
        var file = await folder.CreateFileAsync(@"Captured.jpg", Windows.Storage.CreationCollisionOption.GenerateUniqueName);
        await mediaCaptureMgr.CapturePhotoToStorageFileAsync(captureSettings, file);
        Img.Source = new BitmapImage(new Uri(@file.Path));
        await file.CopyAsync(folder1);
    }

无法在宏碁平板电脑的xaml应用程序中获得最大分辨率的相机

在这里只是猜测-而不是使用VideoPreview来获得您的分辨率,您应该尝试使用Photo:

//res = mediaCaptureMgr.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview);
res = mediaCaptureMgr.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo);