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. Programatically create Bitmap file: How To???

Programatically create Bitmap file: How To???

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestiongraphicstutorial
4 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.
  • J Offline
    J Offline
    JHAKAS
    wrote on last edited by
    #1

    Hi i am doing following: From my function SaveAsBitmap CClientDC dc(this); MemDC.Detach (); MemDC.CreateCompatibleDC(&dc); m_WfrBmp.Detach (); m_WfrBmp.CreateCompatibleBitmap(&dc, 860, 1100); CBitmap *pOldBitmap = (CBitmap *)MemDC.SelectObject(&m_WfrBmp); MemDC.SetMapMode(MM_LOENGLISH); // MemDC.PatBlt(0, 0, 860, 1100, WHITENESS); MemDC.SetBkMode (TRANSPARENT); MemDC.SetBkColor (RGB(255,255,255)); MemDC.Rectangle (100,100,400,400); // Now save the bitmap to the BMP file Filename ="C:\\12.bmp"; CDIBSectionLite dib; HBITMAP hnd = (HBITMAP)m_WfrBmp.GetSafeHandle (); dib.SetBitmap (hnd); dib.Save(Filename); I am getting Black bitmaps only..... What is the problem... Any help/suggestions Leave your mark wherever you go

    V K J 3 Replies Last reply
    0
    • J JHAKAS

      Hi i am doing following: From my function SaveAsBitmap CClientDC dc(this); MemDC.Detach (); MemDC.CreateCompatibleDC(&dc); m_WfrBmp.Detach (); m_WfrBmp.CreateCompatibleBitmap(&dc, 860, 1100); CBitmap *pOldBitmap = (CBitmap *)MemDC.SelectObject(&m_WfrBmp); MemDC.SetMapMode(MM_LOENGLISH); // MemDC.PatBlt(0, 0, 860, 1100, WHITENESS); MemDC.SetBkMode (TRANSPARENT); MemDC.SetBkColor (RGB(255,255,255)); MemDC.Rectangle (100,100,400,400); // Now save the bitmap to the BMP file Filename ="C:\\12.bmp"; CDIBSectionLite dib; HBITMAP hnd = (HBITMAP)m_WfrBmp.GetSafeHandle (); dib.SetBitmap (hnd); dib.Save(Filename); I am getting Black bitmaps only..... What is the problem... Any help/suggestions Leave your mark wherever you go

      V Offline
      V Offline
      V 0
      wrote on last edited by
      #2

      get your header info and write your bitmap pixel per pixel (binary so use fwrite) NOTE: write away like BGR and NOT RGB. For some reason it is that way. (think memory access time is the reason, but I'm not sure) Find some info on the net about the structure of a bmp file. good luck. "If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix

      1 Reply Last reply
      0
      • J JHAKAS

        Hi i am doing following: From my function SaveAsBitmap CClientDC dc(this); MemDC.Detach (); MemDC.CreateCompatibleDC(&dc); m_WfrBmp.Detach (); m_WfrBmp.CreateCompatibleBitmap(&dc, 860, 1100); CBitmap *pOldBitmap = (CBitmap *)MemDC.SelectObject(&m_WfrBmp); MemDC.SetMapMode(MM_LOENGLISH); // MemDC.PatBlt(0, 0, 860, 1100, WHITENESS); MemDC.SetBkMode (TRANSPARENT); MemDC.SetBkColor (RGB(255,255,255)); MemDC.Rectangle (100,100,400,400); // Now save the bitmap to the BMP file Filename ="C:\\12.bmp"; CDIBSectionLite dib; HBITMAP hnd = (HBITMAP)m_WfrBmp.GetSafeHandle (); dib.SetBitmap (hnd); dib.Save(Filename); I am getting Black bitmaps only..... What is the problem... Any help/suggestions Leave your mark wherever you go

        K Offline
        K Offline
        KarstenK
        wrote on last edited by
        #3

        Maybe you should Get the bits of the MemDc X| Try this @ home. (B&B)

        1 Reply Last reply
        0
        • J JHAKAS

          Hi i am doing following: From my function SaveAsBitmap CClientDC dc(this); MemDC.Detach (); MemDC.CreateCompatibleDC(&dc); m_WfrBmp.Detach (); m_WfrBmp.CreateCompatibleBitmap(&dc, 860, 1100); CBitmap *pOldBitmap = (CBitmap *)MemDC.SelectObject(&m_WfrBmp); MemDC.SetMapMode(MM_LOENGLISH); // MemDC.PatBlt(0, 0, 860, 1100, WHITENESS); MemDC.SetBkMode (TRANSPARENT); MemDC.SetBkColor (RGB(255,255,255)); MemDC.Rectangle (100,100,400,400); // Now save the bitmap to the BMP file Filename ="C:\\12.bmp"; CDIBSectionLite dib; HBITMAP hnd = (HBITMAP)m_WfrBmp.GetSafeHandle (); dib.SetBitmap (hnd); dib.Save(Filename); I am getting Black bitmaps only..... What is the problem... Any help/suggestions Leave your mark wherever you go

          J Offline
          J Offline
          John R Shaw
          wrote on last edited by
          #4

          I hope there is nothing attched before you make those calls to Detach() or your program will have resource leaks. After drawing to the bitmap via Rectangle, select pOldBitmap into MemDC. If either function SetBitmap() or Save() needs to select it into a DC, then neither one can do it until MemDC releases ownership. A bitmap can only be selected into one DC at a time. INTP

          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