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. Loading .PNG image windows GDI

Loading .PNG image windows GDI

Scheduled Pinned Locked Moved C / C++ / MFC
graphics
10 Posts 6 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.
  • H Offline
    H Offline
    Hanan888
    wrote on last edited by
    #1

    this is what I do:

    HBITMAP hbm;
    hbm = (HBITMAP)LoadImage(NULL, L"./image1.**bmp**", IMAGE\_BITMAP, 0, 0,
    LR\_LOADFROMFILE|LR\_CREATEDIBSECTION);
    

    This works on .bmp files. But I wish to load .png files.

    D 1 Reply Last reply
    0
    • H Hanan888

      this is what I do:

      HBITMAP hbm;
      hbm = (HBITMAP)LoadImage(NULL, L"./image1.**bmp**", IMAGE\_BITMAP, 0, 0,
      LR\_LOADFROMFILE|LR\_CREATEDIBSECTION);
      

      This works on .bmp files. But I wish to load .png files.

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Have you considered using CImage?

      "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

      H 1 Reply Last reply
      0
      • D David Crow

        Have you considered using CImage?

        "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

        H Offline
        H Offline
        Hanan888
        wrote on last edited by
        #3

        I'm trying to use DirectDraw inteface. CImage is considerable. I tried to use it and got messed in the HDC stuff.

        R 1 Reply Last reply
        0
        • H Hanan888

          I'm trying to use DirectDraw inteface. CImage is considerable. I tried to use it and got messed in the HDC stuff.

          R Offline
          R Offline
          Rajesh R Subramanian
          wrote on last edited by
          #4

          Hanan888 wrote:

          I tried to use it and got messed in the HDC stuff.

          May be if you could show us the mess, someone may help you clean it up.

          Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP

          M H 2 Replies Last reply
          0
          • R Rajesh R Subramanian

            Hanan888 wrote:

            I tried to use it and got messed in the HDC stuff.

            May be if you could show us the mess, someone may help you clean it up.

            Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP

            M Offline
            M Offline
            Maximilien
            wrote on last edited by
            #5

            dear god no!!

            Maximilien Lincourt Your Head A Splode - Strong Bad

            1 Reply Last reply
            0
            • R Rajesh R Subramanian

              Hanan888 wrote:

              I tried to use it and got messed in the HDC stuff.

              May be if you could show us the mess, someone may help you clean it up.

              Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP

              H Offline
              H Offline
              Hanan888
              wrote on last edited by
              #6

              Here is some mess: First look then I'll detail:

                          CImage image
                          PAINTSTRUCT ps;
              	HDC hDC = BeginPaint (m\_hWnd, &ps) ;
                (line 4)  //image = iter->second.m\_pStaticData->m\_Texture; -> **this image was created previously but essentially by the same way like below**
              (line5) image.Load(L"./image.png");
              	image.Draw(hDC,  (int) iter->second.m\_pStaticData->m\_UL.x, (int)                            
                                      iter->second.m\_pStaticData->m\_UL.y);
              	//image.BitBlt(hDC,0,0);
              	EndPaint(m\_hWnd, &ps);
              

              This is 'below':

              CImage image;
              image.Load(L"./image.png");
              pStatData->m_Texture = image;

              The bottom line - no picture were painted. Painted all white. (line 4) crashed. (line 4) and (line 5) behave differently, can't understand why. Perhaps there are some 'unwritten rules' for HDC stuff, I don't know them, I totally admit some sort of ignorance. :)

              M CPalliniC 2 Replies Last reply
              0
              • H Hanan888

                Here is some mess: First look then I'll detail:

                            CImage image
                            PAINTSTRUCT ps;
                	HDC hDC = BeginPaint (m\_hWnd, &ps) ;
                  (line 4)  //image = iter->second.m\_pStaticData->m\_Texture; -> **this image was created previously but essentially by the same way like below**
                (line5) image.Load(L"./image.png");
                	image.Draw(hDC,  (int) iter->second.m\_pStaticData->m\_UL.x, (int)                            
                                        iter->second.m\_pStaticData->m\_UL.y);
                	//image.BitBlt(hDC,0,0);
                	EndPaint(m\_hWnd, &ps);
                

                This is 'below':

                CImage image;
                image.Load(L"./image.png");
                pStatData->m_Texture = image;

                The bottom line - no picture were painted. Painted all white. (line 4) crashed. (line 4) and (line 5) behave differently, can't understand why. Perhaps there are some 'unwritten rules' for HDC stuff, I don't know them, I totally admit some sort of ignorance. :)

                M Offline
                M Offline
                Mark Salsbery
                wrote on last edited by
                #7

                GDI has nothing to do with DirectDraw. Check the return value from the CImage::Load() call....it's probably failing since you're passing an invalid path. Mark

                Mark Salsbery Microsoft MVP - Visual C++ :java:

                1 Reply Last reply
                0
                • H Hanan888

                  Here is some mess: First look then I'll detail:

                              CImage image
                              PAINTSTRUCT ps;
                  	HDC hDC = BeginPaint (m\_hWnd, &ps) ;
                    (line 4)  //image = iter->second.m\_pStaticData->m\_Texture; -> **this image was created previously but essentially by the same way like below**
                  (line5) image.Load(L"./image.png");
                  	image.Draw(hDC,  (int) iter->second.m\_pStaticData->m\_UL.x, (int)                            
                                          iter->second.m\_pStaticData->m\_UL.y);
                  	//image.BitBlt(hDC,0,0);
                  	EndPaint(m\_hWnd, &ps);
                  

                  This is 'below':

                  CImage image;
                  image.Load(L"./image.png");
                  pStatData->m_Texture = image;

                  The bottom line - no picture were painted. Painted all white. (line 4) crashed. (line 4) and (line 5) behave differently, can't understand why. Perhaps there are some 'unwritten rules' for HDC stuff, I don't know them, I totally admit some sort of ignorance. :)

                  CPalliniC Offline
                  CPalliniC Offline
                  CPallini
                  wrote on last edited by
                  #8

                  Hanan888 wrote:

                  L"./image.png"

                  this should probably be _T(".\\image.png"). :) forget it.

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                  This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

                  In testa che avete, signor di Ceprano?

                  D 1 Reply Last reply
                  0
                  • CPalliniC CPallini

                    Hanan888 wrote:

                    L"./image.png"

                    this should probably be _T(".\\image.png"). :) forget it.

                    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #9

                    I seem to recall that string literals can use either single slashes or double backslashes. I've not bothered to confirm this, however.

                    "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                    "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                    CPalliniC 1 Reply Last reply
                    0
                    • D David Crow

                      I seem to recall that string literals can use either single slashes or double backslashes. I've not bothered to confirm this, however.

                      "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                      CPalliniC Offline
                      CPalliniC Offline
                      CPallini
                      wrote on last edited by
                      #10

                      I made a test, you're right. :)

                      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

                      In testa che avete, signor di Ceprano?

                      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