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.