locked
Error while capturing photo by camera

    Question

  • I am developing an Windows Store App in WP8.1. I need to take photo through camera and save it and use it for showing but it throws exception everytime.

    Link to my project is Link to my project

    My code is--

        async private void capturePhoto_Tapped(object sender, TappedRoutedEventArgs e)
                {
                    try
                    {
                        MediaCapture mediaCapture = new MediaCapture();

                        StorageFile sf = await ApplicationData.Current.LocalFolder.CreateFileAsync("My Picture", CreationCollisionOption.GenerateUniqueName);
                        ImageEncodingProperties img = new ImageEncodingProperties();
                        await mediaCapture.CapturePhotoToStorageFileAsync(img, sf);
                    }
                    catch
                    {

                    }
                }

    It throws an exception Object must be initailized and if I use InitalizeAsync it shows System.Exception and message is Text related to the Exception could not be found.If I use this code

        private static async Task<DeviceInformation> GetCameraID(Windows.Devices.Enumeration.Panel desired)
                {
                    DeviceInformation deviceID = (await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture))
                        .FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == desired);

                    if (deviceID != null) return deviceID;
                    else throw new Exception(string.Format("Camera of type {0} doesn't exist.", desired));
                }

                async private void InitCamera_Click(object sender, RoutedEventArgs e)
                {
                    var cameraID = await GetCameraID(Windows.Devices.Enumeration.Panel.Back);
                    var captureManager = new MediaCapture();
                    await captureManager.InitializeAsync(new MediaCaptureInitializationSettings
                    {
                        StreamingCaptureMode = StreamingCaptureMode.Video,
                        PhotoCaptureSource = PhotoCaptureSource.Photo,
                        AudioDeviceId = string.Empty,
                        VideoDeviceId = cameraID.Id
                    });
                    StorageFile sf = await ApplicationData.Current.LocalFolder.CreateFileAsync("My Picture", CreationCollisionOption.GenerateUniqueName);
                    ImageEncodingProperties img = new ImageEncodingProperties();
                    await captureManager.CapturePhotoToStorageFileAsync(img, sf);
                }

    I found the error ------ The requested attribute was not found. (Exception from HRESULT: 0xC00D36E6)--
     Can anybody help? I just need to capture photo using camera and save it for use

                                                    
    • Edited by RohitrkKUmar Thursday, February 05, 2015 10:29 AM Added sample project
    Wednesday, February 04, 2015 1:22 PM

All replies

  • Hello,

    This is a very generic error and the cause depends on the API call that is generating the error. What API is causing the error?

    If I remember correctly photo mode and video streaming mode are mutually exclusive. Try setting the PhotoCaptureSource to VideoPreview.

    I hope this helps,

    James


    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Wednesday, February 04, 2015 11:07 PM
    Moderator
  • It shoes error -----The requested attribute was not found. (Exception from HRESULT: 0xC00D36E6)---------
    Thursday, February 05, 2015 4:47 AM
  • Hello,

    Unfortunately that doesn't answer my question. What function are you calling that returns the error?

    -James


    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Thursday, February 05, 2015 9:07 PM
    Moderator