示例#1
0
文件: Font.cs 项目: pareshkapdiya/OCR
        public void TrimBy(char c, int addToTop, int addToBottom)
        {
            if (!loaded)
            {
                Load();
            }

            Bitmap image = GetChar(c);

            int top    = -1;
            int bottom = image.Height - 1;

            for (int y = 0; y < image.Height; y++)
            {
                bool free = true;

                for (int x = 0; x < image.Width; x++)
                {
                    if (BitmapProcessor.ColorsEqual(image.GetPixel(x, y), Color.Black))
                    {
                        free = false;
                        break;
                    }
                }

                if (free)
                {
                    if (top == y - 1)
                    {
                        top = y;
                    }
                }
                else
                {
                    bottom = y;
                }
            }

            foreach (CharCollection cc in chars)
            {
                foreach (Char ch in cc.chars)
                {
                    Bitmap bmp = ch.bmp;
                    BitmapProcessor.Copy(ref bmp, new Rectangle(0, Math.Max(top + 1 - addToTop, 0), bmp.Width, Math.Min(bottom - top + addToBottom, bmp.Height - 1)));
                    ch.bmp = bmp;
                }
            }
        }