简体   繁体   中英

Draw a String at the upper right corner of an Image

I want to get Point X and Y values so that I can draw a String on the upper right corner. I am doing it:

string str = "A quick brown fox is absent";
pointX = Convert.ToInt32(img.Width - str.Length);
pointX = pointX - 20; //so that I have 20 pixels after the string
pointY = 20; // 20 pixels from the top

The resulting Image is:

在此输入图像描述

But I want this:

在此输入图像描述

(though the string isn't clear, edited with Paint)

Any help is appreciated.

Update:

font: Calibri
size: 20

Edit my code or example code is needed.

您应该使用Graphics.MeasureString而不是str.Length

In addition to what LB suggested, you should look into both StringAlignment and LineAlignment . Check that out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM