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. PNG image in Dialog box

PNG image in Dialog box

Scheduled Pinned Locked Moved C / C++ / MFC
help
9 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.
  • G Offline
    G Offline
    ganesh dp
    wrote on last edited by
    #1

    I have to diaplay one png image in dialog box(like bmp in picture control). any can help me... my image has some transparent things... if change it into bmp format than it won't be transparent so what i have to for diaplaying png image in dialog

    C S 2 Replies Last reply
    0
    • G ganesh dp

      I have to diaplay one png image in dialog box(like bmp in picture control). any can help me... my image has some transparent things... if change it into bmp format than it won't be transparent so what i have to for diaplaying png image in dialog

      C Offline
      C Offline
      Code o mat
      wrote on last edited by
      #2

      Use CxImage[^].

      > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

      G 1 Reply Last reply
      0
      • G ganesh dp

        I have to diaplay one png image in dialog box(like bmp in picture control). any can help me... my image has some transparent things... if change it into bmp format than it won't be transparent so what i have to for diaplaying png image in dialog

        S Offline
        S Offline
        Stuart Dootson
        wrote on last edited by
        #3
        1. Create a 'picture control' to hold the picture

        2. Derive a class from CStatic that'll draw the picture. It should declare a message map and handle WM_PAINT and use a CImage to hold the image. Note the call to TransparentBlt, which (as I've coded it) assumes that the top-;peft pixel of hte image is the transparent colour:

          class MyPic : public CStatic
          {
          public:
          MyPic();
          protected:
          afx_msg void OnPaint();
          DECLARE_MESSAGE_MAP()
          private:
          CImage image_;
          };
          MyPic::MyPic()
          {
          image_.Load(png filename);
          }
          void MyPic::OnPaint()
          {
          PAINTSTRUCT ps;
          CDC * drawDC = BeginPaint(&ps);
          CRect rcClient;
          GetClientRect(&rcClient);
          image_.TransparentBlt(*drawDC, rcClient, CRect(0, 0, image_.GetWidth(), image_.GetHeight()), image_.GetPixel(0, 0));
          EndPaint(&ps);
          }

        3. Declare a member variable wfor the picture control that is of the type you've just made.

        4. See your picture be displayed!

        G 1 Reply Last reply
        0
        • S Stuart Dootson
          1. Create a 'picture control' to hold the picture

          2. Derive a class from CStatic that'll draw the picture. It should declare a message map and handle WM_PAINT and use a CImage to hold the image. Note the call to TransparentBlt, which (as I've coded it) assumes that the top-;peft pixel of hte image is the transparent colour:

            class MyPic : public CStatic
            {
            public:
            MyPic();
            protected:
            afx_msg void OnPaint();
            DECLARE_MESSAGE_MAP()
            private:
            CImage image_;
            };
            MyPic::MyPic()
            {
            image_.Load(png filename);
            }
            void MyPic::OnPaint()
            {
            PAINTSTRUCT ps;
            CDC * drawDC = BeginPaint(&ps);
            CRect rcClient;
            GetClientRect(&rcClient);
            image_.TransparentBlt(*drawDC, rcClient, CRect(0, 0, image_.GetWidth(), image_.GetHeight()), image_.GetPixel(0, 0));
            EndPaint(&ps);
            }

          3. Declare a member variable wfor the picture control that is of the type you've just made.

          4. See your picture be displayed!

          G Offline
          G Offline
          ganesh dp
          wrote on last edited by
          #4

          Cimage is in VC6.0? why because i am getting error

          S 1 Reply Last reply
          0
          • C Code o mat

            Use CxImage[^].

            > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

            G Offline
            G Offline
            ganesh dp
            wrote on last edited by
            #5

            I already tried this using following code but that image lost it's transparency and looks like bmp HBITMAP m_bitmap = NULL; CxImage image("myfile.png", CXIMAGE_FORMAT_PNG); ... CDC* hdc = m_picture.GetDC(); HBITMAP m_bitmap = image.MakeBitmap(hdc->m_hDC); HBITMAP hOldBmp = m_picture.SetBitmap(m_bitmap); if (hOldBmp) DeleteObject(hOldBmp); if (hdc->m_hDC) m_picture.ReleaseDC(hdc); ... if (m_bitmap) DeleteObject(m_bitmap);

            C 1 Reply Last reply
            0
            • G ganesh dp

              Cimage is in VC6.0? why because i am getting error

              S Offline
              S Offline
              Stuart Dootson
              wrote on last edited by
              #6

              ganesh.dp wrote:

              Cimage is in VC6.0?

              Probably not - but you didn't say you were using 10-11 year old software. CImage is definitely in VS.NET 2003 - and that's the oldest VS I have.

              G 1 Reply Last reply
              0
              • S Stuart Dootson

                ganesh.dp wrote:

                Cimage is in VC6.0?

                Probably not - but you didn't say you were using 10-11 year old software. CImage is definitely in VS.NET 2003 - and that's the oldest VS I have.

                G Offline
                G Offline
                ganesh dp
                wrote on last edited by
                #7

                so any other solution?

                S 1 Reply Last reply
                0
                • G ganesh dp

                  I already tried this using following code but that image lost it's transparency and looks like bmp HBITMAP m_bitmap = NULL; CxImage image("myfile.png", CXIMAGE_FORMAT_PNG); ... CDC* hdc = m_picture.GetDC(); HBITMAP m_bitmap = image.MakeBitmap(hdc->m_hDC); HBITMAP hOldBmp = m_picture.SetBitmap(m_bitmap); if (hOldBmp) DeleteObject(hOldBmp); if (hdc->m_hDC) m_picture.ReleaseDC(hdc); ... if (m_bitmap) DeleteObject(m_bitmap);

                  C Offline
                  C Offline
                  Code o mat
                  wrote on last edited by
                  #8

                  Ah, you won't get transparent blitting from the picture control (which is a CStatic actually), look at Stuart Dootson's post. You will have to do the blitting yourself, i recommend using CxImage's own blitting methods.

                  > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

                  1 Reply Last reply
                  0
                  • G ganesh dp

                    so any other solution?

                    S Offline
                    S Offline
                    Stuart Dootson
                    wrote on last edited by
                    #9

                    CImage is just a wrapper around a GDI+ Image[^] - you could try using GDI+ - you will need to get a version of the Platform that a) is compatible with VS6, and b) contains GDI+. As this Platform SDK[^] is the last one that works with VS6, I guess it's your best option.

                    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