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. CBitmap (LoadBitmap is not working)

CBitmap (LoadBitmap is not working)

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsquestion
6 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.
  • A Offline
    A Offline
    Anonymous
    wrote on last edited by
    #1

    CBitmap mainBitmap; int nX1=mainBitmap.LoadBitmap("C:\\a.bmp"); "mainBitmap.LoadBitmap" return value is 0, means this function is not working well. Can u tell me from where i wrong.? if i use BitmapID like IDD_BITMAP, then LoadBitmap works well. but if i give the file name then it not works well. Actually i want to load a bitmap, but VC Bitmap drawing editor did not supports all the wanted color. so i made a bitmap in paint brush and now i want to load it. waiting for the answer

    S 7 2 Replies Last reply
    0
    • A Anonymous

      CBitmap mainBitmap; int nX1=mainBitmap.LoadBitmap("C:\\a.bmp"); "mainBitmap.LoadBitmap" return value is 0, means this function is not working well. Can u tell me from where i wrong.? if i use BitmapID like IDD_BITMAP, then LoadBitmap works well. but if i give the file name then it not works well. Actually i want to load a bitmap, but VC Bitmap drawing editor did not supports all the wanted color. so i made a bitmap in paint brush and now i want to load it. waiting for the answer

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

      I assume you working in MFC. Her Loadbitmap is declared as follow... BOOL LoadBitmap( LPCTSTR lpszResourceName ); BOOL LoadBitmap( UINT nIDResource ); Both tis function asume a resource ID. This resource ID can be a textvalue or UINT value. To load a bitmap from a file you can just call Win32 LoadBitmap API function (or LoadImage). On success then you attach it to the the CBitamp object.

      A 1 Reply Last reply
      0
      • S Sigmund

        I assume you working in MFC. Her Loadbitmap is declared as follow... BOOL LoadBitmap( LPCTSTR lpszResourceName ); BOOL LoadBitmap( UINT nIDResource ); Both tis function asume a resource ID. This resource ID can be a textvalue or UINT value. To load a bitmap from a file you can just call Win32 LoadBitmap API function (or LoadImage). On success then you attach it to the the CBitamp object.

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        I have too checked what u say, but no progress HBITMAP hBitmap=LoadBitmap(AfxGetApp()->m_hInstance,"C:\\a.bmp"); int nX=GetLastError(); return value is 1814, means "The specified resource name cannot be found in the image file. " Although file is present at the required address. any help ?

        S 1 Reply Last reply
        0
        • A Anonymous

          I have too checked what u say, but no progress HBITMAP hBitmap=LoadBitmap(AfxGetApp()->m_hInstance,"C:\\a.bmp"); int nX=GetLastError(); return value is 1814, means "The specified resource name cannot be found in the image file. " Although file is present at the required address. any help ?

          S Offline
          S Offline
          Sigmund
          wrote on last edited by
          #4

          Try... HANDLE LoadImage( HINSTANCE hinst, // handle to instance LPCTSTR lpszName, // image to load UINT uType, // image type int cxDesired, // desired width int cyDesired, // desired height UINT fuLoad // load options ); and set the hinst to NULL and lpszName to the filname you load,uType to IMAGE_BITMAP, fuLoad to LR_LOADFROMFILE. For other parameter and options look it up in MSDN. On success attach it (cast from HANDLE to HBITMAP).

          A 1 Reply Last reply
          0
          • S Sigmund

            Try... HANDLE LoadImage( HINSTANCE hinst, // handle to instance LPCTSTR lpszName, // image to load UINT uType, // image type int cxDesired, // desired width int cyDesired, // desired height UINT fuLoad // load options ); and set the hinst to NULL and lpszName to the filname you load,uType to IMAGE_BITMAP, fuLoad to LR_LOADFROMFILE. For other parameter and options look it up in MSDN. On success attach it (cast from HANDLE to HBITMAP).

            A Offline
            A Offline
            Ahmad99
            wrote on last edited by
            #5

            now it works according to my expectation. thanks a lot....

            1 Reply Last reply
            0
            • A Anonymous

              CBitmap mainBitmap; int nX1=mainBitmap.LoadBitmap("C:\\a.bmp"); "mainBitmap.LoadBitmap" return value is 0, means this function is not working well. Can u tell me from where i wrong.? if i use BitmapID like IDD_BITMAP, then LoadBitmap works well. but if i give the file name then it not works well. Actually i want to load a bitmap, but VC Bitmap drawing editor did not supports all the wanted color. so i made a bitmap in paint brush and now i want to load it. waiting for the answer

              7 Offline
              7 Offline
              73Zeppelin
              wrote on last edited by
              #6

              CBitmap::LoadBitmap() converts the bitmap to the screen's bit depth therefore if you use CBitmap::LoadBitmap() to load the bitmap, the colors will be reduced to the bit depth of the main screen and you won't be able to access the pixels directly. To avoid these problems, load the bitmap as a DIBSection instead and attach the DIBSection to the CBitmap.

              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