Created
May 30, 2017 21:07
-
-
Save tocsoft/321548765955d3b5599096011ca1d9d6 to your computer and use it in GitHub Desktop.
Text Transformation With ImageSharp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void DrawText(Graphics graphics) | |
{ | |
using(Font font = new Font("Arial", 20, FontStyle.Regular, GraphicsUnit.Pixel)) | |
{ | |
// draw string as text without transformation | |
using(Brush brush = new SolidBrush(Color.Blue)) | |
graphics.DrawString("Draw as text without transformation", font, brush, new PointF(10,10)); | |
// draw string as text with transformation | |
GraphicsContainer container = graphics.BeginContainer(); | |
graphics.TranslateTransform(10,40); | |
graphics.RotateTransform(15); | |
using(Brush brush = new SolidBrush(Color.Green)) | |
graphics.DrawString("Draw as text with transformation", font, brush, PointF.Empty); | |
graphics.EndContainer(container); | |
// draw string as path | |
using (GraphicsPath path = new GraphicsPath()) | |
using (Brush brush = new SolidBrush(Color.Red)) | |
{ | |
path.AddString("Draw as path without transformation", font.FontFamily, (int) font.Style, | |
20, new PointF(10, 70), StringFormat.GenericTypographic); | |
graphics.FillPath(brush, path); | |
} | |
// draw string as path with transformation | |
container = graphics.BeginContainer(); | |
graphics.TranslateTransform(10, 100); | |
graphics.RotateTransform(15); | |
using (GraphicsPath path = new GraphicsPath()) | |
using (Brush brush = new SolidBrush(Color.Fuchsia)) | |
{ | |
path.AddString("Draw as path with transformation", font.FontFamily, (int) font.Style, | |
20, PointF.Empty, StringFormat.GenericTypographic); | |
graphics.FillPath(brush, path); | |
} | |
graphics.EndContainer(container); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment