WPF 将图片进行灰度处理

原文: WPF 将图片进行灰度处理

处理前:image      处理后:image

这个功能使用使用了 FormatConvertedBitmap(为BitmapSource提供像素格式转换功能)

代码如下:

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;
    }
}

猜你喜欢

转载自www.cnblogs.com/lonelyxmas/p/9689167.html
WPF