windows-phone-8.1flashlightlumia-imaging-sdk

windows phone 8.1 dispaly PreviewFrame and calculate mean value of red pixels for every frame


Currently I'm using Lumia.Imaging to get preview frame and display it.

I create new method "GetPreview()" to go though pixels, find red pixel and than I would like to calculate mean value of red pixels for every frame.

My problem is that when I'm going through pixel there are lags in app :(


Solution

  • Instead of inspecting all pixels after the Lumia Imaging SDK has processed the image, but before you invalidate the bitmap you could:

        await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.High, () => {                
        var analysisTask = Task.Run(() => getPreview());
    
        previewImage.Source = _writeableBitmap; // previewImage is an image element in MainPage.xaml
        _writeableBitmap.Invalidate(); // force the PreviewBitmap to redraw
    
        await analysisTask;
        });
    

    This way the task of analysing the image doesn't block the update on the screen. Of course this option might not be viable if you need the result of the analysis in the rendering chain itself.