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. How to display a bitmap file using CBitmap class?

How to display a bitmap file using CBitmap class?

Scheduled Pinned Locked Moved C / C++ / MFC
graphicstutorialquestion
3 Posts 3 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.
  • P Offline
    P Offline
    P_JAYAPRAKASH
    wrote on last edited by
    #1

    I have one BMP file. i want to load that bmp file into a form. Please tell me the procedure. Thanks JP ALL THINGS ARE POSSIBLE UNTIL THEY ARE PROVED IMPOSSIBLE-AND EVEN THE IMPOSSIBLE MAY ONLY BE SO,AS OF NOW

    V U 2 Replies Last reply
    0
    • P P_JAYAPRAKASH

      I have one BMP file. i want to load that bmp file into a form. Please tell me the procedure. Thanks JP ALL THINGS ARE POSSIBLE UNTIL THEY ARE PROVED IMPOSSIBLE-AND EVEN THE IMPOSSIBLE MAY ONLY BE SO,AS OF NOW

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

      In the OnDraw function write codes as follow CBitmap img; img.LoadBitmap(IDB_IMG);//IDB_IMG is ID of the resource. CDC * pMemDC=new CDC; pMemDC->CreateCompatibleDC(pDC);//pDC pointer to DC of current window pMemDC->SelectObject(&startImg); pDC->StretchBlt(0,0,cr.right,cr.bottom,pMemDC,0,0,1024,768,SRCCOPY); delete pMemDC; I am a Chinese and my English is very poor,so I wish you correct my mistake. YangXiaowei(China)

      1 Reply Last reply
      0
      • P P_JAYAPRAKASH

        I have one BMP file. i want to load that bmp file into a form. Please tell me the procedure. Thanks JP ALL THINGS ARE POSSIBLE UNTIL THEY ARE PROVED IMPOSSIBLE-AND EVEN THE IMPOSSIBLE MAY ONLY BE SO,AS OF NOW

        U Offline
        U Offline
        User 953354
        wrote on last edited by
        #3

        CString szFilename("path to ur bmp file"); HBITMAP hBmp = (HBITMAP)::LoadImage(NULL,szFilename, IMAGE_BITMAP,0,0, LR_LOADFROMFILE|LR_CREATEDIBSECTION); CBitmap bmp; bmp.Attach(hBmp); CClientDC dc(this); CDC bmDC; bmDC.CreateCompatibleDC(&dc); CBitmap *pOldbmp = bmDC.SelectObject(&bmp); BITMAP bi; bmp.GetBitmap(&bi); dc.StretchBlt (0,0,500,500,&bmDC,0,0,bi.bmWidth ,bi.bmHeight,SRCCOPY); // please see the parameters for StretchBlt() and pass them accordingly bmDC.SelectObject(pOldbmp);

        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