Article From:https://www.cnblogs.com/lonelyxmas/p/9689167.html
WPF: grayscale processing of images.

Before the treatment:image      After treatment:image

 

This function is used.FormatConvertedBitmap(byBitmapSourceProviding pixel format conversion function

 

The code is as follows:

 

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        Image img = new Image();
        BitmapImage bitmapImage = new BitmapImage(new Uri(“D:\\Face.jpg”));

        FormatConvertedBitmap newFormatedBitmapSource = new FormatConvertedBitmap();
        newFormatedBitmapSource.BeginInit();
        newFormatedBitmapSource.Source = bitmapImage;
        newFormatedBitmapSource.DestinationFormat = PixelFormats.Gray8;
        newFormatedBitmapSource.EndInit();

        img.Source = newFormatedBitmapSource;
        this.Content = img;
    }
}

Link of this Article: WPF processes grayscale images.

Leave a Reply

Your email address will not be published. Required fields are marked *