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;
        }

最新文章

  1. 窗口 - dialog - 与后端交互
  2. Eclipse中修改Web项目的URL访问路径
  3. Bootstrap布局设计
  4. 启用WCF测试客户端的相关技巧
  5. 转发:maven打包时始终出现以下提示:-source 1.3 中不支持泛型(请使用 -source 5 或更高版本以启用泛型)
  6. jsp+servlet 上传图片实例
  7. [Centos]openvpn 服务端的安装(easy-rsa3)
  8. 跨域问题实践总结!下( [HTML5] postMessage+服务器端(反向代理服务器+CORS Cross-Origin Resource Sharing))
  9. djongo:Django和MongoDB连接器
  10. Kafka权威指南 读书笔记之(四)Kafka 消费者一一从 Kafka读取数据
  11. Ubuntu 16.04 升级git
  12. IPV4地址分类
  13. python中的print()、str()和repr()的区别
  14. Alpha冲刺第8天
  15. ARKit从入门到精通(8)-ARKit捕捉平地
  16. SAP MM/FI 自动过账实现 OBYC 接口执行
  17. dynamic解析Http xml格式响应数据
  18. html中引入另一个html文件
  19. 初识CSS(1)
  20. Django 之基础续

热门文章

  1. HDU-2844:Coins(多重背包+二进制优化)
  2. 母版页 MasterPage
  3. Python 3 利用 Dlib 实现摄像头人脸检测特征点标定
  4. 数据库MySql在python中的使用
  5. Linux(Contos7.5)环境搭建之Linux远程登录(一)
  6. sql server block如何查询并kill
  7. loadrunner socket协议问题归纳(1)
  8. PHP autoload与spl_autoload自动加载机制的深入理解
  9. BETA阶段冲刺
  10. MDL