CameraPreviewImageSource空预览框

时间:2015-02-24 18:34:27

标签: windows-phone-8.1 win-universal-app lumia-imaging-sdk nokia-imaging-sdk

我在下面的代码中剪切和粘贴了关于如何使用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效果很好!

1 个答案:

答案 0 :(得分:2)

我担心你在Lumia Imaging SDK 2.0.184中看到了一个错误。问题仅出现在某些相机型号上,仅在8.1 /通用应用程序上出现。 Silverlight应用程序不受此问题的影响。

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

  

修复了CameraPreviewImageSource在与某些相机型号一起使用时抛出的ArgumentOutOfRangeException。