Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Problem rotating AND centring text on a bitmap

Problem rotating AND centring text on a bitmap

Scheduled Pinned Locked Moved C#
graphicshelptutorialquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Peter Trevor
    wrote on last edited by
    #1

    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.

    L 1 Reply Last reply
    0
    • P Peter Trevor

      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.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      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


      P 1 Reply Last reply
      0
      • L Luc Pattyn

        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


        P Offline
        P Offline
        Peter Trevor
        wrote on last edited by
        #3

        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.

        L 1 Reply Last reply
        0
        • P Peter Trevor

          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.

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          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


          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups