A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© aisini 金牌黑马   /  2014-7-26 16:03  /  842 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

   网上几种算法中速度相对较快的
  1. public static Bitmap MakeGrayscale(Bitmap original)
  2. {
  3.     //create a blank bitmap the same size as original
  4.     Bitmap newBitmap = new Bitmap(original.Width, original.Height);

  5.     //get a graphics object from the new image
  6.     Graphics g = Graphics.FromImage(newBitmap);

  7.     //create the grayscale ColorMatrix
  8.     System.Drawing.Imaging.ColorMatrix colorMatrix = new System.Drawing.Imaging.ColorMatrix(
  9.        new float[][]
  10.       {
  11.          new float[] {.3f, .3f, .3f, 0, 0},
  12.          new float[] {.59f, .59f, .59f, 0, 0},
  13.          new float[] {.11f, .11f, .11f, 0, 0},
  14.          new float[] {0, 0, 0, 1, 0},
  15.          new float[] {0, 0, 0, 0, 1}
  16.       });

  17.     //create some image attributes
  18.     System.Drawing.Imaging.ImageAttributes attributes = new System.Drawing.Imaging.ImageAttributes();

  19.     //set the color matrix attribute
  20.     attributes.SetColorMatrix(colorMatrix);

  21.     //draw the original image on the new image
  22.     //using the grayscale color matrix
  23.     g.DrawImage(original, new Rectangle(0, 0, original.Width, original.Height), 0, 0, original.Width, original.Height, GraphicsUnit.Pixel, attributes);

  24.     //dispose the Graphics object
  25.     g.Dispose();
  26.     return newBitmap;
  27. }
复制代码



0 个回复

您需要登录后才可以回帖 登录 | 加入黑马