WPF里使用FormatConvertedBitmap将图片转换成黑白图片
来源:互联网 发布:淘宝虚拟物品怎么退款 编辑:程序博客网 时间:2024/04/30 13:45
public FormatConvertedBitmapExample()
{
///// Create a BitmapImage and set it's DecodePixelWidth to 200. Use /////
///// this BitmapImage as a source for other BitmapSource objects. /////
BitmapImage myBitmapImage = new BitmapImage();
// BitmapSource objects like BitmapImage can only have their properties
// changed within a BeginInit/EndInit block.
myBitmapImage.BeginInit();
myBitmapImage.UriSource = new Uri(@"sampleImages/WaterLilies.jpg",UriKind.Relative);
// To save significant application memory, set the DecodePixelWidth or
// DecodePixelHeight of the BitmapImage value of the image source to the desired
// height or width of the rendered image. If you don't do this, the application will
// cache the image as though it were rendered as its normal size rather then just
// the size that is displayed.
// Note: In order to preserve aspect ratio, set DecodePixelWidth
// or DecodePixelHeight but not both.
myBitmapImage.DecodePixelWidth = 200;
myBitmapImage.EndInit();
////////// Convert the BitmapSource to a new format ////////////
// Use the BitmapImage created above as the source for a new BitmapSource object
// which is set to a gray scale format using the FormatConvertedBitmap BitmapSource.
// Note: New BitmapSource does not cache. It is always pulled when required.
FormatConvertedBitmap newFormatedBitmapSource = new FormatConvertedBitmap();
// BitmapSource objects like FormatConvertedBitmap can only have their properties
// changed within a BeginInit/EndInit block.
newFormatedBitmapSource.BeginInit();
// Use the BitmapSource object defined above as the source for this new
// BitmapSource (chain the BitmapSource objects together).
newFormatedBitmapSource.Source = myBitmapImage;
// Set the new format to Gray32Float (grayscale).
newFormatedBitmapSource.DestinationFormat = PixelFormats.Gray32Float;
newFormatedBitmapSource.EndInit();
// Create Image Element
Image myImage = new Image();
myImage.Width = 200;
//set image source
myImage.Source = newFormatedBitmapSource;
// Add Image to the UI
StackPanel myStackPanel = new StackPanel();
myStackPanel.Children.Add(myImage);
this.Content = myStackPanel;
}
- WPF里使用FormatConvertedBitmap将图片转换成黑白图片
- android 将图片转换成黑白图片
- 将图片转换为黑白图片的例子
- CSS3将彩色图片转换成黑白图片
- VB彩色BMP图片转换为黑白图片
- 怎样使用PS将彩色图片转为黑白图片
- wpf/silverlight 将元件转换成图片放入剪切板
- 浅谈JavaScript和Canvas实现彩色图片转换成黑白图片
- Android中如何将res里的图片转换成Bitmap.
- Android如何通过代码将res里的图片转换成drawable.
- 使用CSS将网站、图片转换成黑白的…
- php使用gd库将文字转换成图片
- 使用CSS将图片转换成黑白(灰色、置灰)
- JAVA使用pdfbox将pdf转换成图片
- 使用CSS将图片转换成黑白(灰色、置灰)
- 使用CSS将图片转换成黑白(灰色、置灰)
- 使用CSS将图片转换成黑白(灰色、置灰)
- 如何使用PDF转换器将PDF转换成图片
- Membership角色与权限管理 [5]
- 中联通宣布3G业务10月1日正式商用 套餐共分九档
- VC++项目开发全程实录【配套源码+视频教程】
- Windows开机自动启动SVN服务
- 若干面试题目
- WPF里使用FormatConvertedBitmap将图片转换成黑白图片
- mini 2440TEST 之MMU.C解读
- 构建高性能J2EE应用的十个技巧
- 格式化时间,获得系统时间方法
- Membership角色与权限管理 [6]
- Linux select()详解
- Tips: 注释多行JCL
- September, 28
- 数据库数据库(sqlserver,db2,oracle)的jdbc连接总结