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 / C++ / MFC
  4. creating bitmap

creating bitmap

Scheduled Pinned Locked Moved C / C++ / MFC
graphicstutorial
10 Posts 6 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.
  • R Offline
    R Offline
    rjkg
    wrote on last edited by
    #1

    I want to create the rgb24 or rgb32 bitmap having some text(example "sometext") on it . the lenght of the bitmap should be the font size and width be the length of the text("sometext").

    Rajesh

    S H 2 Replies Last reply
    0
    • R rjkg

      I want to create the rgb24 or rgb32 bitmap having some text(example "sometext") on it . the lenght of the bitmap should be the font size and width be the length of the text("sometext").

      Rajesh

      S Offline
      S Offline
      SandipG
      wrote on last edited by
      #2

      You can use Graphics::MeasureString for this purpose. If you need accurate width and height read this article[^]

      Regards, Sandip.

      R 1 Reply Last reply
      0
      • S SandipG

        You can use Graphics::MeasureString for this purpose. If you need accurate width and height read this article[^]

        Regards, Sandip.

        R Offline
        R Offline
        rjkg
        wrote on last edited by
        #3

        but my question how to create bitmap of desired size without GDI+ from scratch

        Rajesh

        M 1 Reply Last reply
        0
        • R rjkg

          but my question how to create bitmap of desired size without GDI+ from scratch

          Rajesh

          M Offline
          M Offline
          MANISH RASTOGI
          wrote on last edited by
          #4

          Use CreateBitmap API.

          R 1 Reply Last reply
          0
          • M MANISH RASTOGI

            Use CreateBitmap API.

            R Offline
            R Offline
            rjkg
            wrote on last edited by
            #5

            can you sugggest me the last three parameter for creating 24bit rgb and write some text over it

            Rajesh

            R 1 Reply Last reply
            0
            • R rjkg

              can you sugggest me the last three parameter for creating 24bit rgb and write some text over it

              Rajesh

              R Offline
              R Offline
              Rane
              wrote on last edited by
              #6

              Try out the below code piece...

              CDC* pDC = GetDC();

              CDC memDC;
              memDC.CreateCompatibleDC(pDC);

              CBitmap bitmap;
              bitmap.CreateCompatibleBitmap(pDC, 100, 100);

              CBitmap* pOldBitmap = memDC.SelectObject((CBitmap*)&bitmap);

              //
              // Write the Text using memDC
              //

              pDC->BitBlt(0, 0, 100, 100, &memDC, 0, 0, SRCCOPY);

              memDC.SelectObject((CBitmap*)pOldBitmap);

              ReleaseDC(pDC);

              Regards, Rane

              R 1 Reply Last reply
              0
              • R Rane

                Try out the below code piece...

                CDC* pDC = GetDC();

                CDC memDC;
                memDC.CreateCompatibleDC(pDC);

                CBitmap bitmap;
                bitmap.CreateCompatibleBitmap(pDC, 100, 100);

                CBitmap* pOldBitmap = memDC.SelectObject((CBitmap*)&bitmap);

                //
                // Write the Text using memDC
                //

                pDC->BitBlt(0, 0, 100, 100, &memDC, 0, 0, SRCCOPY);

                memDC.SelectObject((CBitmap*)pOldBitmap);

                ReleaseDC(pDC);

                Regards, Rane

                R Offline
                R Offline
                rjkg
                wrote on last edited by
                #7

                can you send me the code using pure win32 api not MFC

                Rajesh

                R M 2 Replies Last reply
                0
                • R rjkg

                  can you send me the code using pure win32 api not MFC

                  Rajesh

                  R Offline
                  R Offline
                  Rane
                  wrote on last edited by
                  #8

                  Its pretty easy..Follow the above programming structure and replace the MFC functions with the equivalent Win32 APIs.This will be a good excercise to learn about the win32 multimedia/graphic APIs !. p.s : I know it is little time consuming ;P Regards, Rane

                  1 Reply Last reply
                  0
                  • R rjkg

                    can you send me the code using pure win32 api not MFC

                    Rajesh

                    M Offline
                    M Offline
                    Mark Salsbery
                    wrote on last edited by
                    #9

                    Rane's code makes a bitmap the same format as the display. If you want to guarantee 24bpp or 32bpp you can use CreateDIBSection() instead of CreateCompatibleBitmap(). Mark

                    Mark Salsbery Microsoft MVP - Visual C++ :java:

                    1 Reply Last reply
                    0
                    • R rjkg

                      I want to create the rgb24 or rgb32 bitmap having some text(example "sometext") on it . the lenght of the bitmap should be the font size and width be the length of the text("sometext").

                      Rajesh

                      H Offline
                      H Offline
                      Hamid Taebi
                      wrote on last edited by
                      #10

                      Is this[^] helpful?

                      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