예제 #1
0
        internal static void DrawElements(BitmapEx bitmap, params TextDrawElement[] elements)
        {
            using (var graphics = bitmap.CreateGraphics())
            {
                int yPosition = 0;
                for (var index = 0; index < elements.Length; index++)
                {
                    TextDrawElement element = elements[index];

                    var maxHeight  = bitmap.Height * element.Percentage / 100;
                    var textHeight = (element.Text != null)?FontEstimation.EstimateFontSize(bitmap, element.FontFamily, element.Text, alterHeight: maxHeight):0;

                    using (var brush = new SolidBrush(element.Color))
                        using (Font textFont = (textHeight > 0)?new Font(element.FontFamily, textHeight, GraphicsUnit.Pixel): null)
                        {
                            var size = graphics.MeasureString(element.Text, textFont);

                            float x = 0;
                            if (element.Alignment == StringAlignment.Center)
                            {
                                x = (bitmap.Width - size.Width) / 2;
                            }
                            else if (element.Alignment == StringAlignment.Far)
                            {
                                x = (bitmap.Width - size.Width);
                            }

                            graphics.DrawString(element.Text, textFont, brush, x, yPosition + (maxHeight - size.Height) / 2);
                        }

                    yPosition += maxHeight;
                }
            }
        }
예제 #2
0
        public static void DrawTexts(BitmapEx bitmap, FontFamily fontFamily, string l1, string l2, string textExample, Color color)
        {
            var textHeight = FontEstimation.EstimateFontSize(bitmap, fontFamily, textExample);

            using (var graphics = bitmap.CreateGraphics())
                using (var whiteBrush = new SolidBrush(color))
                    using (var textFont = new Font(fontFamily, textHeight, GraphicsUnit.Pixel))
                    {
                        var size = graphics.MeasureString(l1, textFont);
                        graphics.DrawString(l1, textFont, whiteBrush, bitmap.Width - size.Width, 0);

                        size = graphics.MeasureString(l2, textFont);
                        graphics.DrawString(l2, textFont, whiteBrush, bitmap.Width - size.Width, bitmap.Height / 2);
                    }
        }
예제 #3
0
        public static void DrawIconAndText(BitmapEx bitmap, FontFamily iconFontFamily, string iconSymbol, FontFamily textFontFamily, string text, string textExample, Color color)
        {
            var textHeight  = (text != null)?FontEstimation.EstimateFontSize(bitmap, textFontFamily, textExample):0;
            var imageHeight = (int)(bitmap.Height * 0.9 - textHeight);

            using (var graphics = bitmap.CreateGraphics())
                using (var whiteBrush = new SolidBrush(color))
                    using (Font textFont = (textHeight > 0)?new Font(textFontFamily, textHeight, GraphicsUnit.Pixel): null)
                        using (Font imageFont = new Font(iconFontFamily, imageHeight, GraphicsUnit.Pixel))
                        {
                            var size = graphics.MeasureString(text, textFont);
                            graphics.DrawString(text, textFont, whiteBrush, bitmap.Width - size.Width, bitmap.Height - size.Height);

                            graphics.DrawString(iconSymbol, imageFont, whiteBrush, 0, 0);
                        }
        }
예제 #4
0
        public static void DrawText(BitmapEx bitmap, FontFamily fontFamily, string text, Color color)
        {
            var height = FontEstimation.EstimateFontSize(bitmap, fontFamily, text);

            using (var graphics = bitmap.CreateGraphics())
                using (var whiteBrush = new SolidBrush(color))
                    using (var font = new Font(fontFamily, height, GraphicsUnit.Pixel))
                    {
                        var size = graphics.MeasureString(text, font);
                        if (size.Width / size.Height > 5)
                        {
                            var splittedText = SplitText(text);
                            if (splittedText != text)
                            {
                                DrawText(bitmap, fontFamily, splittedText, color);
                                return;
                            }
                        }

                        graphics.DrawString(text, font, whiteBrush, (bitmap.Width - size.Width) / 2, (bitmap.Height - size.Height) / 2);
                    }
        }