0

I'm trying to do a image processing software and for the moment I'm stuck on this. I've open an image in my first canvas, and now I want to take the image and add some filters on it. Contrast, saturation and so on, and then to see it on the second canvas. But my main problem is that I can't find out how to use pixels from my first canvas and manipulate them. How can I do this the easy way? Thanks.

private void openImage_OnClick(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();

            dlg.InitialDirectory = "c:\\";
            dlg.DefaultExt = ".jpeg";
            dlg.Filter = "Image files (*.png;*.jpg;*.jpeg)|*.png;*.jpg;*.jpeg";


            Nullable<bool> result = dlg.ShowDialog();

            if (result == true)
            {
                string filename = dlg.FileName;
                ImageBrush brush = new ImageBrush();
                brush.ImageSource = new BitmapImage(new Uri(@filename, UriKind.Relative));
                CanvasOriginalImage.Background = brush;
            }
        }
navyad
  • 3,752
  • 7
  • 47
  • 88
  • Create a WriteableBitmap from the BitmapImage you already have, and manipulate its pixels. Then use it as ImageSource of an ImageBrush, or Source of a Image element. – Clemens Jun 14 '19 at 13:20
  • You can create bitmap from canvas (look [here](https://stackoverflow.com/q/5851168/1997232)) and then use some library to apply filters or do pixel manipulation yourself. Also check out [shader effects](https://stackoverflow.com/q/1728346/1997232), those are applied as effect in real time so maybe you don't even need second canvas. – Sinatr Jun 14 '19 at 13:22
  • I still can't figure it how to do that. I've watched that topic and still got no idea on how to transform my canvas to bitmap and then manipulate those pixels. He's having problems with it and getting black pictures. May you help me with some code? Thanks. – Radu Raducu Jun 15 '19 at 09:57

0 Answers0