zoukankan      html  css  js  c++  java
  • 解析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;
            }

  • 相关阅读:
    vscode source control provider not registered
    MAC NVM 安装
    《高效前端:Web 高效编程与优化实践》学习笔记
    回显服务端/client
    图像处理系列(1):測地线动态轮廓(geodesic active contour)
    Pro Android学习笔记(一三八):Home Screen Widgets(4):App Widget Provider
    怎样传输SE63的翻译内容
    <html>
    概率dp sgu495
    Android Afinal框架学习(一) FinalDb 数据库操作
  • 原文地址:https://www.cnblogs.com/zkwarrior/p/4954810.html
Copyright © 2011-2022 走看看