解析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#,彩 , 像灰度化
0
投稿

猜你喜欢

  • Spring Boot conditional注解用法详解

    2022-03-19 02:32:25
  • HashMap 和 Hashtable的区别

    2022-11-01 06:34:47
  • C#网络编程基础之进程和线程详解

    2023-03-22 07:38:32
  • 详解SpringBoot自定义配置与整合Druid

    2023-07-24 20:20:28
  • SpringMVC @RequestBody自动转json Http415错误的解决

    2022-09-12 13:12:34
  • 解决javaWEB中前后台中文乱码问题的3种方法

    2023-03-22 22:39:26
  • 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
  • springmvc后台基于@ModelAttribute获取表单提交的数据

    2023-08-05 12:29:35
  • Java中GUI工具包AWT和Swing用法介绍

    2022-02-06 09:02:35
  • C#创建自定义控件及添加自定义属性和事件使用实例详解

    2022-05-30 02:10:12
  • SpringCloud Hystrix-Dashboard仪表盘的实现

    2023-03-16 18:38:03
  • java 引用传递的三种类型小结

    2023-09-03 03:59:47
  • 详解java倒计时三种简单实现方式

    2023-11-11 16:47:38
  • c#分页读取GB文本文件实例

    2021-09-13 10:18:39
  • mybatis-plus分页查询的实现示例

    2023-11-25 04:57:57
  • Java AWT中常用的三种布局管理器详解

    2023-02-11 20:55:25
  • SpringCloud Feign配置应用详细介绍

    2023-07-14 04:23:03
  • Java模拟有序链表数据结构的示例

    2023-09-26 22:25:30
  • asp之家 软件编程 m.aspxhome.com