UWP: The component cannot be found (Exception from HRESULT: 0x88982F50)

 ̄綄美尐妖づ 提交于 2019-12-12 22:19:18

问题


I sometimes get an error when i try to take a picture within my uwp app. This error is very hard to reproduce and happend a few min ago on desktop platform. I used a hovercam to retrieve the imagebuffer.

    public async Task<IBuffer> TakePhotoAsync()
    {
        Debug.WriteLine("taking picture...");

        using (var stream = new InMemoryRandomAccessStream())
        {
            try
            {
                await mediaCapture.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), stream);
                Debug.WriteLine("captured to stream");
            }
            catch (Exception e)
            {
                ExceptionHandler.Instance.HandleException(e);
            }

            //rotate img
            return await GetRotatedIBuffer(stream);

        }
    }

    public async Task<IBuffer> GetRotatedIBuffer(IRandomAccessStream stream)
    {
        //rotate img
        using (var imageStream = new InMemoryRandomAccessStream())
        {
            BitmapDecoder dec = await BitmapDecoder.CreateAsync(stream);
            BitmapEncoder enc = await BitmapEncoder.CreateForTranscodingAsync(stream, dec);

            BitmapRotation rotation = BitmapRotation.None;
            switch (App.settings.DefaultCamera.Rotation)
            {
                case VideoRotation.Clockwise180Degrees:
                    rotation = BitmapRotation.Clockwise180Degrees;
                    break;
                case VideoRotation.Clockwise270Degrees:
                    rotation = BitmapRotation.Clockwise270Degrees;
                    break;
                case VideoRotation.Clockwise90Degrees:
                    rotation = BitmapRotation.Clockwise90Degrees;
                    break;
            }

            enc.BitmapTransform.Rotation = rotation;
            await enc.FlushAsync();

            try
            {
                await RandomAccessStream.CopyAsync(stream,imageStream);
            }
            catch (Exception ex)
            {
                ExceptionHandler.Instance.HandleException(ex);
            }

            return await StreamHelpers.StreamToIBuffer(imageStream);
        }
    }

output:

taking picture...
Exception thrown: 'System.Runtime.InteropServices.COMException' in               mscorlib.ni.dll
WinRT information: Started
System.Runtime.InteropServices.COMException (0xC00D36B2): The request is not valid in current state
Started
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at KNFB_Reader_Windows10.KNFBCamera.<TakePhotoAsync>d__25.MoveNext()
Exception thrown: 'System.Exception' in mscorlib.ni.dll
Exception thrown: 'System.Exception' in mscorlib.ni.dll
Exception thrown: 'System.Exception' in mscorlib.ni.dll
Exception thrown: 'System.Exception' in mscorlib.ni.dll

The component cannot be found. (Exception from HRESULT: 0x88982F50)

来源:https://stackoverflow.com/questions/41826340/uwp-the-component-cannot-be-found-exception-from-hresult-0x88982f50

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!