Click here to Skip to main content
15,888,269 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
While using Windows 8 Pro Tablet ( Thinkpad 2) to capture an image using its Primary camera, the maximum resolution that I get is 640X480. I have tried but could not succeed to get higher resolution. Please suggest a workaround.

C#
using Windows.Foundation;
using Windows.Media.Capture;
using Windows.Storage;
using Windows.Storage.AccessCache;
using Windows.Storage.Streams;
using System.Windows.Controls;
using Windows.Media;
using System.Windows.Media.Imaging;
using System;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
using System.Windows;
using System.IO;
using System.Runtime.InteropServices.WindowsRuntime;



namespace Final
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : System.Windows.Window
    {
      //  MainWindow rootPage = MainWindow.; 
        //private Windows.Foundation.Collections.IPropertySet appSettings;
        //private const String photoKey = "capturedPhoto"; 
        public MainWindow()
        {
            InitializeComponent();
           // appSettings = ApplicationData.Current.LocalSettings.Values;
          //  ResetButton.Visibility = Visibility.Collapsed; 
        }

        private async void CapturePhoto_Click(object sender, System.Windows.RoutedEventArgs e)
        {

            var capture = new MediaCapture();
            // Find the camera device id to use
            string deviceId = "";
            var devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(Windows.Devices.Enumeration.DeviceClass.VideoCapture);
            for (var i = 0; i < devices.Count; i++)
            {
                Console.WriteLine(devices[i]);
                deviceId = devices[i].Id;
            }

            

            var settings = new MediaCaptureInitializationSettings();
            settings.AudioDeviceId = "";
            settings.VideoDeviceId = deviceId;
            try
            {
                settings.PhotoCaptureSource = Windows.Media.Capture.PhotoCaptureSource.Auto;
                settings.StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.Video;
                await capture.InitializeAsync(settings);

                Windows.Media.MediaProperties.VideoEncodingProperties resolutionMax = null;
                int max = 0;
                var resolutions = capture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo);
                for (var i = 0; i < resolutions.Count; i++)
                {
                    Windows.Media.MediaProperties.VideoEncodingProperties res = (Windows.Media.MediaProperties.VideoEncodingProperties)resolutions[i];
                    Console.WriteLine("resolution : " + res.Width + "x" + res.Height);
                    if (res.Width * res.Height > max)
                    {
                        max = (int)(res.Width * res.Height);
                        resolutionMax = res;
                    }
                }

                await capture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, resolutionMax);

                Windows.Media.MediaProperties.ImageEncodingProperties imageProperties = Windows.Media.MediaProperties.ImageEncodingProperties.CreateJpeg();
                var fPhotoStream = new InMemoryRandomAccessStream();

                await capture.CapturePhotoToStreamAsync(imageProperties, fPhotoStream);
                await fPhotoStream.FlushAsync();
                fPhotoStream.Seek(0);

                byte[] bytes = new byte[fPhotoStream.Size];
                await fPhotoStream.ReadAsync(bytes.AsBuffer(), (uint)fPhotoStream.Size, InputStreamOptions.None);

                BitmapImage bitmapImage = new BitmapImage();
                MemoryStream byteStream = new MemoryStream(bytes);
                Image image = new System.Windows.Controls.Image();
                bitmapImage.BeginInit();
                bitmapImage.StreamSource = byteStream;
                bitmapImage.EndInit();
                image.Source = bitmapImage;
                CapturedPhoto.Source = bitmapImage;
                msg.Content = resolutionMax.Width;
            }
            catch (Exception ex)
            {
                msg.Content = ex.Message.ToString();
            }
      } 
        }

        
    }
}
Posted
Updated 25-Oct-13 12:43pm
v2
Comments
Matt T Heffron 25-Oct-13 18:44pm    
This appears to be a duplicate of: http://www.codeproject.com/Questions/674113/While-using-Windows-8-Pro-Tablet-Thinkpad-2-to-cap

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900