解析C#彩 * 像灰度化算法的实现代码详解
时间:2022-01-26 07:34:55
代码如下所示:
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;
}
标签:c#,彩 , 像灰度化
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Spring Boot conditional注解用法详解
2022-03-19 02:32:25
![](https://img.aspxhome.com/file/2023/5/61795_0s.png)
HashMap 和 Hashtable的区别
2022-11-01 06:34:47
C#网络编程基础之进程和线程详解
2023-03-22 07:38:32
![](https://img.aspxhome.com/file/2023/7/78147_0s.png)
详解SpringBoot自定义配置与整合Druid
2023-07-24 20:20:28
![](https://img.aspxhome.com/file/2023/9/96269_0s.jpg)
SpringMVC @RequestBody自动转json Http415错误的解决
2022-09-12 13:12:34
![](https://img.aspxhome.com/file/2023/0/63070_0s.jpg)
解决javaWEB中前后台中文乱码问题的3种方法
2023-03-22 22:39:26
![](https://img.aspxhome.com/file/2023/7/64807_0s.jpg)
C# 9.0新特性——扩展方法GetEnumerator支持foreach循环
2021-08-27 22:38:09
Java用 Rhino/Nashorn 代替第三方 JSON 转换库
2023-11-04 02:20:26
Idea中maven项目实现登录验证码功能
2023-11-29 16:50:51
![](https://img.aspxhome.com/file/2023/5/60575_0s.png)
springmvc后台基于@ModelAttribute获取表单提交的数据
2023-08-05 12:29:35
![](https://img.aspxhome.com/file/2023/7/71657_0s.jpg)
Java中GUI工具包AWT和Swing用法介绍
2022-02-06 09:02:35
![](https://img.aspxhome.com/file/2023/6/71176_0s.jpg)
C#创建自定义控件及添加自定义属性和事件使用实例详解
2022-05-30 02:10:12
![](https://img.aspxhome.com/file/2023/3/85653_0s.png)
SpringCloud Hystrix-Dashboard仪表盘的实现
2023-03-16 18:38:03
![](https://img.aspxhome.com/file/2023/3/80973_0s.png)
java 引用传递的三种类型小结
2023-09-03 03:59:47
![](https://img.aspxhome.com/file/2023/0/60560_0s.png)
详解java倒计时三种简单实现方式
2023-11-11 16:47:38
![](https://img.aspxhome.com/file/2023/8/62508_0s.png)
c#分页读取GB文本文件实例
2021-09-13 10:18:39
![](https://img.aspxhome.com/file/2023/8/92878_0s.png)
mybatis-plus分页查询的实现示例
2023-11-25 04:57:57
![](https://img.aspxhome.com/file/2023/5/60025_0s.png)
Java AWT中常用的三种布局管理器详解
2023-02-11 20:55:25
![](https://img.aspxhome.com/file/2023/6/65586_0s.png)
SpringCloud Feign配置应用详细介绍
2023-07-14 04:23:03
![](https://img.aspxhome.com/file/2023/7/57497_0s.png)
Java模拟有序链表数据结构的示例
2023-09-26 22:25:30