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. Bitmap question

Bitmap question

Scheduled Pinned Locked Moved C / C++ / MFC
graphicshelptutorialquestion
1 Posts 1 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.
  • C Offline
    C Offline
    Chun Te Ewe
    wrote on last edited by
    #1

    Dear all, This problem of mine has been bugging me crazy. I have to load a 24bit .bmp file and convert it to a 32 bit bmp file. I've manage to load the bitmap file, display it on the screen and even made the code to make it a 32bit bitmap. The problem is to attach the modified bits to the m_bmpBitmap CBitmap object. Then I get the info of the m_bmpBitmap with the BITMAP structure. BITMAP bm; m_bmpBitmap.GetBitmap(&bm); The bm.bmBits is 0x0 which it shouldn't be. All the CreateBitmap() and GetBitmap() funtions return successful but I can't even display the image to screen and I feel it is due to bm.bmBits = 0x0. I've even tried to create a 24 bit bitmap with the same method below and it didn't work too. I would like to be able to view the image that I created and as well as to be able to save it. I welcome any new ideas on how to approach this matter. Many many thanks. Chun Te, Ewe -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ CBitmap m_bmpBitmapOri; CBitmap m_bmpBitmap; BYTE *m_pOriSrc, *m_pSrc; HBITMAP hBitmap = (HBITMAP) ::LoadImage(AfxGetInstanceHandle(), "h:\\logo.bmp" ,IMAGE_BITMAP, 0, 0, R_LOADFROMFILE | LR_CREATEDIBSECTION); m_bmpBitmapOri.Attach(hBitmap); BITMAP bmOri; m_bmpBitmapOri.GetBitmap(&bmOri); // Get the loaded bitmap m_pOriSrc = (BYTE*)bmOri.bmBits; // Pointer to the original bitmap bits // Prepare a new location if(m_pSrc!=NULL) delete [] m_pSrc; m_pSrc = new BYTE[(bmOri.bmHeight+1)*bmOri.bmWidth*4]; ... some code to change from 24bpps to 32 bpps (if needed I can provide) ... if (m_bImageValid) m_bmpBitmap.DeleteObject(); // Creating the image m_bmpBitmap.CreateBitmap( bmOri.bmWidth, bmOri.bmHeight, 1, 32, m_pSrc ); BITMAP bm; // Obtain info regarding bitmap m_bmpBitmap.GetBitmap(&bm); // // Create a device contect to load the bitmap into CDC dcMem; CClientDC pDC(this); dcMem.CreateCompatibleDC(&pDC); dcMem.SelectObject(m_bmpBitmap); pDC.BitBlt(250, 7, bm.bmWidth, bm.bmHeight, &dcMem, 0, 0, SRCCOPY); // Won't display image

    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