protected override void OnPaint(PaintEventArgs e) { Graphics labelGraphics = e.Graphics; labelGraphics.SmoothingMode = smoothingMode; labelGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic; OutlineText m_OutlineText = new OutlineText(); // Text colour, Outline colour, Thickness if (drawOutline) { m_OutlineText.TextOutline(ForeColor, outlineColor, outlineThickness); } else { m_OutlineText.TextNoOutline(ForeColor); } m_OutlineText.EnableShadow(drawShadow); m_OutlineText.SetNullShadow(); if (m_OutlineText.IsShadowEnabled()) { if (drawDiffusedShadow) { m_OutlineText.DiffusedShadow(Color.FromArgb(150, 0, 0, 0), shadowThickness, new Point(shadowOffsetHorizontal, shadowOffsetVertical)); } else { m_OutlineText.Shadow(Color.FromArgb(150, 0, 0, 0), shadowThickness, new Point(shadowOffsetHorizontal, shadowOffsetVertical)); } } if (drawGradient) { float fStartX = 0.0f; float fStartY = 0.0f; float fDestWidth = 0.0f; float fDestHeight = 0.0f; m_OutlineText.MeasureString(labelGraphics, Font.FontFamily, FontStyle.Regular, FontHeight, Text, new Point(0, 0), StringFormat.GenericTypographic, ref fStartX, ref fStartY, ref fDestWidth, ref fDestHeight); LinearGradientBrush gradientBrush = new LinearGradientBrush(new Rectangle(0, 0, (int)fDestWidth, (int)fDestHeight), ForeColor, gradientEndColor, LinearGradientMode.Vertical); if (drawOutline) { m_OutlineText.TextOutline(gradientBrush, outlineColor, outlineThickness); } else { m_OutlineText.TextNoOutline(gradientBrush); } } m_OutlineText.DrawString(labelGraphics, Font.FontFamily, FontStyle.Regular, FontHeight, Text, new Point(0, 0), StringFormat.GenericTypographic); }
private Bitmap TextGradOutline() { OutlineText outlineText = new OutlineText(); outlineText.TextGradOutline(ColorTranslator.FromHtml(modelItem.FontColor), Color.FromArgb(template.OutlineColor1), Color.FromArgb(template.OutlineColor2), template.OutlineThickness1); outlineText.EnableShadow(template.ShadowEnable); if (template.ShadowEnable) { outlineText.Shadow(Color.FromArgb(template.ShadowColor), template.ShadowThickness, new Point(template.ShadowOffsetX, template.ShadowOffsetY)); } Graphics g = Graphics.FromImage(new Bitmap(1, 1)); outlineText.MeasureString(g, fontFamily, FontStyle.Regular, modelItem.FontSize, modelItem.Text, new Point(0, 0), new StringFormat(), ref fStartX, ref fStartY, ref fDestWidth, ref fDestHeight); fDestHeight++; Bitmap image = new Bitmap((int)(fStartX + fDestWidth), (int)(fStartY + fDestHeight)); // FromImage method creates a new Graphics from the specified Image. Graphics graphics = Graphics.FromImage(image); graphics.SmoothingMode = SmoothingMode.AntiAlias; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; LinearGradientBrush gradientBrush = new LinearGradientBrush(new RectangleF(fStartX, fStartY, fDestWidth - (fStartX - 10), fDestHeight - (fStartY - 10)), ColorTranslator.FromHtml(modelItem.FontColor), Color.FromArgb(template.TextColor2), LinearGradientMode.Vertical); if (template.TextGradientEnable) { outlineText.TextGradOutline(gradientBrush, Color.FromArgb(template.OutlineColor1), Color.FromArgb(template.OutlineColor2), template.OutlineThickness1); } outlineText.DrawString(graphics, fontFamily, FontStyle.Regular, modelItem.FontSize, modelItem.Text, new Point(0, 0), new StringFormat()); gradientBrush.Dispose(); graphics.Dispose(); g.Dispose(); return(image); }