1

There is an image in "Image" control. When user taps image control, the color should be extracted of that exact pixel.

This is the code provided by msdn, for Windows Phone 8. In Chroma Key Demo For Windows 8

private async void ViewfinderCanvas_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
    var point = e.GetPosition(ViewfinderCanvas);
    var bitmap = new WriteableBitmap((int)ViewfinderCanvas.ActualWidth, (int)ViewfinderCanvas.ActualHeight);

    using (var source = new CameraPreviewImageSource(App.Camera))
    using (var effect = new FilterEffect(source))
    using (var renderer = new WriteableBitmapRenderer(effect, bitmap, OutputOption.Stretch))
    {
        effect.Filters = new List<IFilter>()
        {
            new RotationFilter(_rotationFilter.RotationAngle)
        };

        await renderer.RenderAsync();

        var picked = bitmap.Pixels[((int)point.Y) * bitmap.PixelWidth + ((int)point.X)];

        _color = new Color
        {
            A = 0xFF,
            R = (byte)((picked & 0x00FF0000) >> 16),
            G = (byte)((picked & 0x0000FF00) >> 8),
            B = (byte)(picked & 0x000000FF)
        };
    }

    ColorBorder.Background = new SolidColorBrush(_color);
}

My edited code,

private void FilteredView_Tapped(object sender, TappedRoutedEventArgs e)
   {
       var Point = e.GetPosition(FilteredView);

       var bitmap = new WriteableBitmap((int)FilteredView.ActualWidth, (int)FilteredView.ActualHeight);





        // ERROR HERE
           var picked = bitmap.Pixels[((int)Point.Y) * bitmap.PixelWidth + ((int)Point.X)];

           _color = new Color
           {
               A = 0xFF,
               R = (byte)((picked & 0x00FF0000) >> 16),
               G = (byte)((picked & 0x0000FF00) >> 8),
               B = (byte)(picked & 0x000000FF)
           };



   }

FilteredView is Image Control. I just need the color at pointer, so I dont use filters etc because it is not of any use here. Also function does not need to be async.

Error says, 'Windows.UI.Xaml.Media.Imaging.WriteableBitmap' does not contain a definition for 'Pixels'.

Project template is Windows Phone 8.1 project.

Lumia Imaging SDK is imported (mentioned if any the Bitmap types are conflicting).

Question: Is this even the right way to do it? If yes then what is possible alternate for using a WriteableBitmap class to access pixels?

Talha
  • 903
  • 8
  • 31

0 Answers0