解析C#彩色图像灰度化算法的实现代码详解
http://www.jb51.net/article/37067.htm
public static Bitmap MakeGrayscale(Bitmap original)
{
//create a blank bitmap the same size as original
Bitmap newBitmap = new Bitmap(original.Width, original.Height);
//get a graphics object from the new image
Graphics g = Graphics.FromImage(newBitmap);
//create the grayscale ColorMatrix
System.Drawing.Imaging.ColorMatrix colorMatrix = new System.Drawing.Imaging.ColorMatrix(
new float[][]
{
new float[] {.3f, .3f, .3f, 0, 0},
new float[] {.59f, .59f, .59f, 0, 0},
new float[] {.11f, .11f, .11f, 0, 0},
new float[] {0, 0, 0, 1, 0},
new float[] {0, 0, 0, 0, 1}
});
//create some image attributes
System.Drawing.Imaging.ImageAttributes attributes = new System.Drawing.Imaging.ImageAttributes();
//set the color matrix attribute
attributes.SetColorMatrix(colorMatrix);
//draw the original image on the new image
//using the grayscale color matrix
g.DrawImage(original, new Rectangle(0, 0, original.Width, original.Height),
0, 0, original.Width, original.Height, GraphicsUnit.Pixel, attributes);
//dispose the Graphics object
g.Dispose();
return newBitmap;
}
最新文章
- 窗口 - dialog - 与后端交互
- Eclipse中修改Web项目的URL访问路径
- Bootstrap布局设计
- 启用WCF测试客户端的相关技巧
- 转发:maven打包时始终出现以下提示:-source 1.3 中不支持泛型(请使用 -source 5 或更高版本以启用泛型)
- jsp+servlet 上传图片实例
- [Centos]openvpn 服务端的安装(easy-rsa3)
- 跨域问题实践总结!下( [HTML5] postMessage+服务器端(反向代理服务器+CORS Cross-Origin Resource Sharing))
- djongo:Django和MongoDB连接器
- Kafka权威指南 读书笔记之(四)Kafka 消费者一一从 Kafka读取数据
- Ubuntu 16.04 升级git
- IPV4地址分类
- python中的print()、str()和repr()的区别
- Alpha冲刺第8天
- ARKit从入门到精通(8)-ARKit捕捉平地
- SAP MM/FI 自动过账实现 OBYC 接口执行
- dynamic解析Http xml格式响应数据
- html中引入另一个html文件
- 初识CSS(1)
- Django 之基础续