Skip to content

ImageSharp -- How do I draw a text to the top of the image? #87

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

You must be logged in to vote

Text has a line high and you are drawing the line at the top not the characters, the reason for this is that different characters within the same font can have wildly different heights and we needs a consistent baseline for rendering.

There was a stack overflow question with a similar issue here https://stackoverflow.com/a/53023454/234855 but the solution was basically this:

/// <param name="text">one or more characters to scale to fill as much of the target image size as required.</param>
/// <param name="targetSize">the size in pixels to generate the image</param>
/// <param name="outputFileName">path/filename where to save the image to</param>
private static void GenerateImage(string text

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@tocsoft
Comment options

Comment options

You must be logged in to vote
1 reply
@tocsoft
Comment options

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