wpf,图片灰化处理

 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>

  

 

 

xmlns:ee="http://schemas.microsoft.com/expression/2010/effects" 


        <Image Margin="0,0,0,49" Source="page2.png" Stretch="None">
            <Image.Effect>
                <ee:MonochromeEffect/>
            </Image.Effect>
        </Image>

 

posted @ 2015-06-24 17:29  莫欺  阅读(496)  评论(0编辑  收藏  举报