博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WPF 将图片进行灰度处理
阅读量:7009 次
发布时间:2019-06-28

本文共 578 字,大约阅读时间需要 1 分钟。

原文:

处理前:      处理后:

 

这个功能使用使用了 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;
    }
}

转载地址:http://usntl.baihongyu.com/

你可能感兴趣的文章