1

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!

Community
  • 1
  • 1
Jano
  • 731
  • 7
  • 18
  • What error exactly are you seeing? – David Božjak Feb 25 '15 at 08:56
  • Hi, the error is the following: The operation attempted to access data outside the valid range (Exception from HRESULT: 0x8000000B) ww:0 hh:0 The thread 0xdb4 has exited with code 0 (0x0). at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at AugmentedReality.MainPage.d__19.MoveNext() This seems to happen as the frame has size 0 x 0 or empty. – Jano Feb 26 '15 at 09:27
  • What device are you working on? I have seen something similar before, but it was device specific... – David Božjak Feb 26 '15 at 15:13
  • Hi, it is a Lumia 930, but again is very strange as with the same device it happen just with Win RT code not using Silverlight . – Jano Feb 26 '15 at 17:04
  • a new version of Lumia Imaging SDK has been released on NuGet (2.0.208). Can you try that one out and see if the problem disappears with the latest? Thanks! – David Božjak Mar 05 '15 at 13:42
  • 1
    Hi, yes updating the SDK solved the problem, Thanks! – Jano Mar 05 '15 at 16:55
  • Great! Sorry I couldn't make any promisses before the update was actually released, as we waren't sure it was the same issue as the bug we have fixed. I will write a reply just in case someone else out there is dealing with the same problem. – David Božjak Mar 06 '15 at 06:59

1 Answers1

2

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.

David Božjak
  • 16,887
  • 18
  • 67
  • 98