Пример #1
0
        public Size GetCharSize(char c, Color backgroundColor)
        {
            Bitmap bmp = new Bitmap(GetChar(c));

            BitmapProcessor.Trim(ref bmp);

            int minY = bmp.Height;
            int maxY = 0;

            for (int y = 0; y < bmp.Height; y++)
            {
                for (int x = 0; x < bmp.Width; x++)
                {
                    Color color = bmp.GetPixel(x, y);
                    if (!BitmapProcessor.ColorsEqual(color, backgroundColor))
                    {
                        if (y < minY)
                        {
                            minY = y;
                        }
                        if (y > maxY)
                        {
                            maxY = y;
                        }
                        break;
                    }
                }
            }

            int width = bmp.Width;

            bmp.Dispose();

            return(new Size(width, maxY - minY + 1));
        }
Пример #2
0
        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;
                }
            }
        }