Skip to content

Is it possible to get ImageSharp to tell you the bounds of text it just rendered? #430

Answered by tocsoft
jez9999 asked this question in Q&A
Discussion options

You must be logged in to vote

https://docs.sixlabors.com/articles/fonts/gettingstarted.html the first example for our getting start docs cover this exact sort of case.

var size = TextMeasurer.MeasureAdvance(parsed.ParsedString, new RichTextOptions(normalFontQnText) {
			Origin = new Vector2(810, 800),
			LayoutMode = LayoutMode.HorizontalTopBottom,
			HorizontalAlignment = HorizontalAlignment.Center,
			VerticalAlignment = VerticalAlignment.Center,
			TextAlignment = TextAlignment.Start,
			WrappingLength = 900,
			TextRuns = parsed.TextRuns,
		} );

is basically what your looking for.

PS this question would have been better asked in ImageSharp.Drawing as its a DrawXXX API or Fonts as its about text metadata.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@jez9999
Comment options

@JimBobSquarePants
Comment options

Answer selected by jez9999
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants