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. Generating Text bitmap from Graphics

Generating Text bitmap from Graphics

Scheduled Pinned Locked Moved C#
graphicstutorialquestion
8 Posts 4 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.
  • A Offline
    A Offline
    azusakt
    wrote on last edited by
    #1

    Hi, All. My application have to generate a text bitmap. The text string is inputted by user, and will be drawn on a panel witin a fixed region. so the string is auto wrapped with multi-line. I would like to save the display text into a bitmap file (same as the preview with auto wrapped). Does anyone know how to do ? Could you please provide me some examples ? Thank you so much !!

    M E G 3 Replies Last reply
    0
    • A azusakt

      Hi, All. My application have to generate a text bitmap. The text string is inputted by user, and will be drawn on a panel witin a fixed region. so the string is auto wrapped with multi-line. I would like to save the display text into a bitmap file (same as the preview with auto wrapped). Does anyone know how to do ? Could you please provide me some examples ? Thank you so much !!

      M Offline
      M Offline
      Martin 0
      wrote on last edited by
      #2

      Hello, Do I understand it write, that you have the Text allready in your panel and make a bitmap (like screenshot) from the panel? Martin

      A 1 Reply Last reply
      0
      • A azusakt

        Hi, All. My application have to generate a text bitmap. The text string is inputted by user, and will be drawn on a panel witin a fixed region. so the string is auto wrapped with multi-line. I would like to save the display text into a bitmap file (same as the preview with auto wrapped). Does anyone know how to do ? Could you please provide me some examples ? Thank you so much !!

        E Offline
        E Offline
        Eduard Keilholz
        wrote on last edited by
        #3

        Create a new Graphis object and use DrawString function....

        .: I love it when a plan comes together :. http://www.zonderpunt.nl

        A 1 Reply Last reply
        0
        • A azusakt

          Hi, All. My application have to generate a text bitmap. The text string is inputted by user, and will be drawn on a panel witin a fixed region. so the string is auto wrapped with multi-line. I would like to save the display text into a bitmap file (same as the preview with auto wrapped). Does anyone know how to do ? Could you please provide me some examples ? Thank you so much !!

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          Use the DrawToBitmap method to draw the control on a Bitmap.

          --- b { font-weight: normal; }

          A 1 Reply Last reply
          0
          • M Martin 0

            Hello, Do I understand it write, that you have the Text allready in your panel and make a bitmap (like screenshot) from the panel? Martin

            A Offline
            A Offline
            azusakt
            wrote on last edited by
            #5

            yes, correct. I have already used the drawString to draw text on Panel. But don't know how to generate a bitmap. Here is my example code for drawing the string: string txt = "AbcdefgHigklmnopqrstuvWxyz.AbcdefgHigklmnopqrstuvWxyz.***(AbcdefgHigklmnopqrstuvWxyz)@#!!!) (AbcdefgHigklmnopqrstuvWxyZ)ZZZZZZZ"; StringFormat drawFormat = new StringFormat(); drawFormat.FormatFlags = StringFormatFlags.DisplayFormatControl; drawFormat.Trimming = StringTrimming.Character; drawFormat.LineAlignment = StringAlignment.Near; // start from top line g.DrawRectangle(Pens.Red, new Rectangle(100, 100, 200, 500)); g.DrawString(txt, f, Brushes.Black, new RectangleF(100, 100, 200, 500), drawFormat);

            M 1 Reply Last reply
            0
            • E Eduard Keilholz

              Create a new Graphis object and use DrawString function....

              .: I love it when a plan comes together :. http://www.zonderpunt.nl

              A Offline
              A Offline
              azusakt
              wrote on last edited by
              #6

              But use DrawString just draw the text on the screen... how can I generate a bitmap as same as the preview on screen? thank you

              1 Reply Last reply
              0
              • G Guffa

                Use the DrawToBitmap method to draw the control on a Bitmap.

                --- b { font-weight: normal; }

                A Offline
                A Offline
                azusakt
                wrote on last edited by
                #7

                Thank you Guffa, I'm sorry, can you give me some example code?

                1 Reply Last reply
                0
                • A azusakt

                  yes, correct. I have already used the drawString to draw text on Panel. But don't know how to generate a bitmap. Here is my example code for drawing the string: string txt = "AbcdefgHigklmnopqrstuvWxyz.AbcdefgHigklmnopqrstuvWxyz.***(AbcdefgHigklmnopqrstuvWxyz)@#!!!) (AbcdefgHigklmnopqrstuvWxyZ)ZZZZZZZ"; StringFormat drawFormat = new StringFormat(); drawFormat.FormatFlags = StringFormatFlags.DisplayFormatControl; drawFormat.Trimming = StringTrimming.Character; drawFormat.LineAlignment = StringAlignment.Near; // start from top line g.DrawRectangle(Pens.Red, new Rectangle(100, 100, 200, 500)); g.DrawString(txt, f, Brushes.Black, new RectangleF(100, 100, 200, 500), drawFormat);

                  M Offline
                  M Offline
                  Martin 0
                  wrote on last edited by
                  #8

                  Hello, You could use the CreateBitmap Method of the panel class. All the best, Martin

                  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