Problem rotating AND centring text on a bitmap
-
I need to place some text rotated at 45 degrees onto a bitmap. The text needs to be centred on a specific point. Placing normal text centred on a point on a bitmap is easy enough, and I’ve googled a number of different solutions to rotating text ... but I can’t rotate *and* centre on a point at the same time. An added complication is the text may sometimes contain CRLFs. Can anyone show me the code how to do this (in VS2005)? Thanks.
-
I need to place some text rotated at 45 degrees onto a bitmap. The text needs to be centred on a specific point. Placing normal text centred on a point on a bitmap is easy enough, and I’ve googled a number of different solutions to rotating text ... but I can’t rotate *and* centre on a point at the same time. An added complication is the text may sometimes contain CRLFs. Can anyone show me the code how to do this (in VS2005)? Thanks.
Hi, this is my view on this: 1. first attempt to paint the text without rotation; the text height can be measured using Graphics.MeasureString; when given the available width it will optionally do word wrapping, and anyway it will calculate the effective width and necessary height. So you know the distance from topleft to center now. 2. you can ask a Graphics to do all transformations for you; first order a translation to the point where your text should be centered; then order a rotation; now draw the string with Graphics.DrawString at location (0,0). That should do it. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in
-
Hi, this is my view on this: 1. first attempt to paint the text without rotation; the text height can be measured using Graphics.MeasureString; when given the available width it will optionally do word wrapping, and anyway it will calculate the effective width and necessary height. So you know the distance from topleft to center now. 2. you can ask a Graphics to do all transformations for you; first order a translation to the point where your text should be centered; then order a rotation; now draw the string with Graphics.DrawString at location (0,0). That should do it. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in
Hi Luc Sorry to sound like a newbie but can you give me the code to show how this is done? I tried but got myself muddled.
-
Hi Luc Sorry to sound like a newbie but can you give me the code to show how this is done? I tried but got myself muddled.
No, sorry, I am not going to create and provide code. That is not how this site works. You do the effort, show some results, then ask specific questions. So I suggest you raise the level of your knowledge where it is lacking by studying serious material (preferably a book) and/or performing some experiments. Hint: when playing with TranslateTransform and RotateTransform, make sure to make your view much larger than you consider necessary, things go out of sight pretty soon, especially if you choose the wrong polarity for some of the factors. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in