Auto center alignment of the nickname #85
Answered
by
tocsoft
sadness-mugetsu
asked this question in
Q&A
-
Beta Was this translation helpful? Give feedback.
Answered by
tocsoft
Apr 29, 2021
Replies: 2 comments 3 replies
-
using var image = new Image<Rgba32>(400, 200);
var userName = "Test test";
var userNameTextWidth = (int)TextMeasurer.Measure(userName, new RendererOptions(font));
var userNameStartPointX = image.Width / 2 - userNameTextWidth / 2;
image.Mutate(x => x.DrawText(userName, font, Color.White, new PointF(userNameStartPointX, 100))); |
Beta Was this translation helpful? Give feedback.
3 replies
-
You can configure the engine with various alignments, the bellow uses the Image image = ...; // create any way you like.
Font font = ...; // see our Fonts library for best practices on retriving one of these.
TextGraphicsOptions options = new TextGraphicsOptions()
{
HorizontalAlignment = HorizontalAlignment.Center // center align
};
IBrush brush = Brushes.Horizontal(Color.Red, Color.Blue);
IPen pen = Pens.DashDot(Color.Green, 5);
string text = "sample text";
int halfImageWidth = image.Width / 2;
// draws a star with Horizontal red and blue hatching with a dash dot pattern outline.
image.Mutate( x=> x.DrawText(options, text, font, brush, pen, new PointF(halfImageWidth, 100)); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
tocsoft
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can configure the engine with various alignments, the bellow uses the
Center
alignment with a drawing point of the center of the image this will cause the text to draw outwards left and right evenly from the point specified.