public static unsafe void GrayscaleImage(BitmapData sourceImage, IntPtr destBuffer)
       {
           int width = sourceImage.Width;
           int height = sourceImage.Height;

           // do the job
           var src = (byte*) sourceImage.Scan0.ToPointer();
           var dst = (byte*) destBuffer.ToPointer();
           int srcOffset = sourceImage.Stride - width*3;

           // for each line
           for (int y = 0; y < height; y++)
           {
               // for each pixel
               for (int x = 0; x < width; x++, src += 3, dst++)
               {
                   // use integer arithmetic to instead of doubles to speed up calculation
                   *dst = (byte) ((2125*src[2] + 7154*src[1] + 721*src[0])/10000);
               }
               src += srcOffset;
           }
       }

相关文章:

  • 2021-08-03
  • 2022-12-23
  • 2021-12-20
  • 2021-07-03
  • 2022-12-23
  • 2022-01-22
  • 2021-12-30
  • 2021-11-19
猜你喜欢
  • 2022-12-23
  • 2021-05-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案