Ejemplo n.º 1
0
        protected static int DeterminePercentageOfBlackPixels(System.Drawing.Bitmap bmp, System.Drawing.Rectangle rect)
        {
            System.Diagnostics.Debug.Assert(bmp.PixelFormat == System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
            System.Drawing.Imaging.BitmapData bmd = bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
            int xOffset = rect.X;
            int yOffset = rect.Y;
            int count   = 0;

            for (int x = 0; x < rect.Width; x++)
            {
                for (int y = 0; y < rect.Height; y++)
                {
                    int pix = bmd.GetPixel(x, y);
                    if (pix == 0)
                    {
                        count++;
                    }
                }
            }
            bmp.UnlockBits(bmd);
            return(count * 100 / (rect.Width * rect.Height));
        }