0

So I'm writing a text on an image with DrawString in a rectangle. My text is written on multiple line in my rectangle. How can I get the pixel position of the last character drawn on my image ? Because this character can be at any Width because of the multiple line. I think it's more easy understand with an image, so I want to get the pixel position here, at the "?":

enter image description here

I tried everything, searched for hours, MeasureString, even OCR, but I didn't find any way to get the pixel position of the last character of the drawn text.

I need this position because I want to append it an image with DrawImage.

tucotraff
  • 61
  • 4
  • You can get a pixelperfect bounds from a graphicspath, but since you won't know where it starts it may not help much.. But searching from the right close to the bottom should work, with a little extra effort.. Do you draw into a Bitmap? GetPixel should do the job.. – TaW Mar 26 '17 at 17:58
  • 1
    You are no doubt letting DrawString() do the word-wrapping. No point in forcing us to guess btw. Very convenient but not compatible with your goal. You have to use StringFormatFlags.NoWrap and use MeasureString() to break up the string into individual lines yourself. – Hans Passant Mar 26 '17 at 18:08
  • Thanks a lot Hans, really helpfull, I will try that right now. – tucotraff Mar 26 '17 at 18:09

0 Answers0