CameraPreviewImageSource 空预览框

CameraPreviewImageSource empty preview frame

我剪切并粘贴了下面关于如何使用 CameraPreviewImageSource 和访问预览缓冲区帧的代码,但不起作用,而且帧缓冲区大小似乎是 0x0,读取 OnPreviewFrameAvailable 事件的 IImageSize 参数的值。

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;
        }
    }

已选择 Package.appxmanifest 上的功能(网络摄像头和麦克风)

在 Silverlight 应用程序上实现 CameraPreviewImageSource 效果很好!

恐怕您看到了 Lumia Imaging SDK 2.0.184 中的错误。该问题仅出现在某些相机型号上,并且仅出现在 8.1/通用应用程序上。 Silverlight 应用程序不受此问题的影响。

该错误已在新发布的 Lumia Imaging SDK 2.0.208 中修复。来自发行说明:

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