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. Converting txt to bmp

Converting txt to bmp

Scheduled Pinned Locked Moved C / C++ / MFC
graphics
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.
  • N Offline
    N Offline
    Nilesh K
    wrote on last edited by
    #1

    Hi, Can anyone suggest a way to convert a text file to bmp at runtime:confused:, I was able to create and save the bitmap file but was unable to append text to it.:sigh:

    - Nilesh "Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw

    PJ ArendsP 1 Reply Last reply
    0
    • N Nilesh K

      Hi, Can anyone suggest a way to convert a text file to bmp at runtime:confused:, I was able to create and save the bitmap file but was unable to append text to it.:sigh:

      - Nilesh "Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw

      PJ ArendsP Offline
      PJ ArendsP Offline
      PJ Arends
      wrote on last edited by
      #2

      Load (or create) the bitmap, select it into a memory DC and use DrawText or TextOut to draw your text onto the bitmap the same as you would draw text onto the screen DC. Select the bitmap out of the DC and save it.


      "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!


      Honoured as one of The Most Helpful Members of 2004

      Within you lies the power for good; Use it!

      N 1 Reply Last reply
      0
      • PJ ArendsP PJ Arends

        Load (or create) the bitmap, select it into a memory DC and use DrawText or TextOut to draw your text onto the bitmap the same as you would draw text onto the screen DC. Select the bitmap out of the DC and save it.


        "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!


        Honoured as one of The Most Helpful Members of 2004

        N Offline
        N Offline
        Nilesh K
        wrote on last edited by
        #3

        already tried that but I don't see any text in the saved bmp file :confused:

        - Nilesh "Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw

        PJ ArendsP 1 Reply Last reply
        0
        • N Nilesh K

          already tried that but I don't see any text in the saved bmp file :confused:

          - Nilesh "Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw

          PJ ArendsP Offline
          PJ ArendsP Offline
          PJ Arends
          wrote on last edited by
          #4

          Show your code.


          "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!


          Honoured as one of The Most Helpful Members of 2004

          Within you lies the power for good; Use it!

          N 1 Reply Last reply
          0
          • PJ ArendsP PJ Arends

            Show your code.


            "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!


            Honoured as one of The Most Helpful Members of 2004

            N Offline
            N Offline
            Nilesh K
            wrote on last edited by
            #5

            CreateBitmap(); m_pMemDC = new CDC; VERIFY( m_pMemDC->CreateCompatibleDC(m_pWinDC) ); m_pOldBitmap = m_pMemDC->SelectObject( &m_Bitmap ); CString str("This is a test message"); CPen cp; cp.CreatePen(PS_SOLID, 2,RGB(255,255,255)); CRect rect; GetClientRect(&rect); m_pMemDC->SelectObject(&cp); m_pMemDC->DrawText(str,str.GetLength(),rect,DT_LEFT); PBITMAPINFO pbi = getInfoStruct(m_Bitmap); CreateBMPFile("test.bmp",pbi,m_Bitmap,m_pMemDC->m_hDC); m_pMemDC->SelectObject(m_pOldBitmap);

            - Nilesh "Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw

            T 1 Reply Last reply
            0
            • N Nilesh K

              CreateBitmap(); m_pMemDC = new CDC; VERIFY( m_pMemDC->CreateCompatibleDC(m_pWinDC) ); m_pOldBitmap = m_pMemDC->SelectObject( &m_Bitmap ); CString str("This is a test message"); CPen cp; cp.CreatePen(PS_SOLID, 2,RGB(255,255,255)); CRect rect; GetClientRect(&rect); m_pMemDC->SelectObject(&cp); m_pMemDC->DrawText(str,str.GetLength(),rect,DT_LEFT); PBITMAPINFO pbi = getInfoStruct(m_Bitmap); CreateBMPFile("test.bmp",pbi,m_Bitmap,m_pMemDC->m_hDC); m_pMemDC->SelectObject(m_pOldBitmap);

              - Nilesh "Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw

              T Offline
              T Offline
              ThatsAlok
              wrote on last edited by
              #6

              Nilesh K. wrote: CreateBMPFile("test.bmp",pbi,m_Bitmap,m_pMemDC->m_hDC); I Believe, Such function doesn't exist in WIndow's Api!. could you show coding for that too, as your problem may be at the time of saving!

              "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

              cheers, Alok Gupta

              N 1 Reply Last reply
              0
              • T ThatsAlok

                Nilesh K. wrote: CreateBMPFile("test.bmp",pbi,m_Bitmap,m_pMemDC->m_hDC); I Believe, Such function doesn't exist in WIndow's Api!. could you show coding for that too, as your problem may be at the time of saving!

                "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                cheers, Alok Gupta

                N Offline
                N Offline
                Nilesh K
                wrote on last edited by
                #7

                CRect rect; CSize size; GetClientRect(&rect); size = rect.Size(); LPBITMAPINFO lpbi; // Fill in the BITMAPINFOHEADER lpbi = (LPBITMAPINFO) new BYTE[sizeof(BITMAPINFOHEADER) + (256 * sizeof(RGBQUAD))]; lpbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); lpbi->bmiHeader.biWidth = size.cx; lpbi->bmiHeader.biHeight = size.cy; lpbi->bmiHeader.biPlanes = 1; lpbi->bmiHeader.biBitCount = 8; lpbi->bmiHeader.biCompression = BI_RGB; lpbi->bmiHeader.biSizeImage = WIDTHBYTES((DWORD)size.cx * 8) * size.cy; lpbi->bmiHeader.biXPelsPerMeter = 0; lpbi->bmiHeader.biYPelsPerMeter = 0; lpbi->bmiHeader.biClrUsed = 0; lpbi->bmiHeader.biClrImportant = 0; // Fill in the color table UINT uUsage = DIB_RGB_COLORS; memcpy( lpbi->bmiColors, m_rgbPalette, sizeof(RGBQUAD) * 256 ); m_pWinDC = new CWindowDC(this); HBITMAP hBitmap = CreateDIBSection( m_pWinDC->m_hDC, lpbi, uUsage, (void **)&m_pBits, NULL, 0 ); delete [] (BYTE *)lpbi; ASSERT(hBitmap != NULL); m_Bitmap.Attach( hBitmap );

                - Nilesh "Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw

                K 1 Reply Last reply
                0
                • N Nilesh K

                  CRect rect; CSize size; GetClientRect(&rect); size = rect.Size(); LPBITMAPINFO lpbi; // Fill in the BITMAPINFOHEADER lpbi = (LPBITMAPINFO) new BYTE[sizeof(BITMAPINFOHEADER) + (256 * sizeof(RGBQUAD))]; lpbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); lpbi->bmiHeader.biWidth = size.cx; lpbi->bmiHeader.biHeight = size.cy; lpbi->bmiHeader.biPlanes = 1; lpbi->bmiHeader.biBitCount = 8; lpbi->bmiHeader.biCompression = BI_RGB; lpbi->bmiHeader.biSizeImage = WIDTHBYTES((DWORD)size.cx * 8) * size.cy; lpbi->bmiHeader.biXPelsPerMeter = 0; lpbi->bmiHeader.biYPelsPerMeter = 0; lpbi->bmiHeader.biClrUsed = 0; lpbi->bmiHeader.biClrImportant = 0; // Fill in the color table UINT uUsage = DIB_RGB_COLORS; memcpy( lpbi->bmiColors, m_rgbPalette, sizeof(RGBQUAD) * 256 ); m_pWinDC = new CWindowDC(this); HBITMAP hBitmap = CreateDIBSection( m_pWinDC->m_hDC, lpbi, uUsage, (void **)&m_pBits, NULL, 0 ); delete [] (BYTE *)lpbi; ASSERT(hBitmap != NULL); m_Bitmap.Attach( hBitmap );

                  - Nilesh "Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw

                  K Offline
                  K Offline
                  khan
                  wrote on last edited by
                  #8

                  CPen cp; cp.CreatePen(PS_SOLID, 2,RGB(255,255,255)); Why write white text? Maybe the color of the bitmap is white: RGB(255,255,255), that is why the text does not show. this is this.

                  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