CameraPreviewImageSource empty preview frame

风格不统一 提交于 2019-12-08 07:50:47

问题


I made cut and paste of the code below about how to use CameraPreviewImageSource and access to preview buffer frames, but do not work and it seems the frame buffer size is 0x0 reading the value of IImageSize parameter of OnPreviewFrameAvailable event.

How to get preview buffer of MediaCapture - Universal app

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {            
        InitializeAsync();
    }

    public async void InitializeAsync()
    {            
        _cameraPreviewImageSource = new CameraPreviewImageSource();  
        await _cameraPreviewImageSource.InitializeAsync(string.Empty);
        var properties = await _cameraPreviewImageSource.StartPreviewAsync();

        var width = 640.0;
        var height = 480;
        _writeableBitmap = new WriteableBitmap((int)width, (int)height);

        _writeableBitmapRenderer = new WriteableBitmapRenderer(_cameraPreviewImageSource, _writeableBitmap);

        Initialized = true;

        _cameraPreviewImageSource.PreviewFrameAvailable += OnPreviewFrameAvailable;
    }

    private async void OnPreviewFrameAvailable(IImageSize args)
    {
        System.Diagnostics.Debug.WriteLine("ww:"+args.Size.Width+" hh:"+args.Size.Height);

        // Prevent multiple rendering attempts at once
        if (Initialized && !_isRendering)
        {
            _isRendering = true;    
            try
            {                    
                await _writeableBitmapRenderer.RenderAsync();                   
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("\n\n"+ex.Message);
                System.Diagnostics.Debug.WriteLine(ex.StackTrace);
            }
            _isRendering = false;
        }
    }

Capabilities (webcam & microphone) on Package.appxmanifest has been selected

Implementing CameraPreviewImageSource on a Silverlight app works great!


回答1:


I am afraid you are (were) seeing a bug in Lumia Imaging SDK 2.0.184. The problem only occured on some camera models and only on 8.1/universal applications. Silverlight applications were not affected by the problem.

The bug has been fixed in the newly released Lumia Imaging SDK 2.0.208. From release notes:

Fixed ArgumentOutOfRangeException being thrown by CameraPreviewImageSource when used with certain camera models.



来源:https://stackoverflow.com/questions/28703586/camerapreviewimagesource-empty-preview-frame

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