private BitmapSource ToGray(BitmapSource source)
{
FormatConvertedBitmap re = new FormatConvertedBitmap();
re.BeginInit();
re.Source = source;
re.DestinationFormat = PixelFormats.Gray8;
re.EndInit();
return re;
}
<Image HorizontalAlignment="Center" Width="30" Height="30" VerticalAlignment="Center" Stretch="None" Margin="0"> <Image.Source> <FormatConvertedBitmap DestinationFormat="Gray8"> <FormatConvertedBitmap.Source> <BitmapImage UriSource="/课本.png" /> </FormatConvertedBitmap.Source> </FormatConvertedBitmap> </Image.Source> <Image.OpacityMask> <ImageBrush> <ImageBrush.ImageSource> <BitmapImage UriSource="/课本.png" /> </ImageBrush.ImageSource> </ImageBrush> </Image.OpacityMask> </Image>
原文:http://www.cnblogs.com/m7777/p/4598232.html