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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How can I get a HBITMAP handle from a CImageList Object?

How can I get a HBITMAP handle from a CImageList Object?

Scheduled Pinned Locked Moved C / C++ / MFC
question
16 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.
  • H Hamid Taebi

    See m_ImageList->GetImageInfo(...); -----------------------And----------- You can use From ExtractIcon(index) for get a hicon of list and draw this icon to a dc and save this dc to a bitmap this code is an idea maybe its not good but if you want to checking this code its working. CImageList* m_ImageList; CBitmap Bmp; m_ImageList=new CImageList(); m_ImageList->Create(32,32, ILC_COLORDDB,0,0); Bmp.LoadBitmap(IDB_BITMAP1); m_ImageList->Add(&Bmp,RGB(100,105,0)); m_ImageList->Add(&Bmp,RGB(100,105,0)); CDC dc; CBitmap p; CImage m; dc.CreateCompatibleDC(GetDC()); p.CreateCompatibleBitmap(GetDC(),32,32); dc.SelectObject(p); for (int i=0;i < m_ImageList->GetImageCount();i++) { dc.DrawIcon(0, 0, m_ImageList->ExtractIcon(i)); //dc.SelectObject(p); m.Attach(p); m.Save("c:\\0.bmp"); m.Detach(); } //now free resources...

    _**


    **_

    WhiteSky


    T Offline
    T Offline
    Tcpip2005
    wrote on last edited by
    #5

    Thank you very much. but there is still a problem. the bmp that saved have a black background. how could I change the back colour into what ever I want?? And It is much better that you don't use CxImage. -- modified at 7:57 Friday 25th August, 2006

    P H 2 Replies Last reply
    0
    • T Tcpip2005

      Thank you very much. but there is still a problem. the bmp that saved have a black background. how could I change the back colour into what ever I want?? And It is much better that you don't use CxImage. -- modified at 7:57 Friday 25th August, 2006

      P Offline
      P Offline
      prasad_som
      wrote on last edited by
      #6

      Tcpip2005 wrote:

      the bmp that saved have a black background. how could I change the back colour into what ever I want??

      You mean to say, you want to change BMP, is it?

      Tcpip2005 wrote:

      And It is much better that you don't use CxImage.

      ??

      Prasad Notifier using ATL

      T 1 Reply Last reply
      0
      • P prasad_som

        Tcpip2005 wrote:

        the bmp that saved have a black background. how could I change the back colour into what ever I want??

        You mean to say, you want to change BMP, is it?

        Tcpip2005 wrote:

        And It is much better that you don't use CxImage.

        ??

        Prasad Notifier using ATL

        T Offline
        T Offline
        Tcpip2005
        wrote on last edited by
        #7

        Yes,change the backgroud colour. change black background into red,for example.

        P 1 Reply Last reply
        0
        • T Tcpip2005

          Thank you very much. but there is still a problem. the bmp that saved have a black background. how could I change the back colour into what ever I want?? And It is much better that you don't use CxImage. -- modified at 7:57 Friday 25th August, 2006

          H Offline
          H Offline
          Hamid Taebi
          wrote on last edited by
          #8

          DrawIcon(you need to calculate x from icons in your listimage,0,m_ImageList->ExtractIcon(i))

          Tcpip2005 wrote:

          It is much better that you don't use CxImage

          ?!CImage

          _**


          **_

          WhiteSky


          T 1 Reply Last reply
          0
          • T Tcpip2005

            Yes,change the backgroud colour. change black background into red,for example.

            P Offline
            P Offline
            prasad_som
            wrote on last edited by
            #9

            I'm not sure, if its possible.

            Prasad Notifier using ATL

            H 1 Reply Last reply
            0
            • P prasad_som

              I'm not sure, if its possible.

              Prasad Notifier using ATL

              H Offline
              H Offline
              Hamid Taebi
              wrote on last edited by
              #10

              Its possible(he needs a little work for it)

              _**


              **_

              WhiteSky


              P 1 Reply Last reply
              0
              • H Hamid Taebi

                Its possible(he needs a little work for it)

                _**


                **_

                WhiteSky


                P Offline
                P Offline
                prasad_som
                wrote on last edited by
                #11

                WhiteSky wrote:

                Its possible(he needs a little work for it)

                ya tru, its more than little.

                Prasad Notifier using ATL

                1 Reply Last reply
                0
                • H Hamid Taebi

                  DrawIcon(you need to calculate x from icons in your listimage,0,m_ImageList->ExtractIcon(i))

                  Tcpip2005 wrote:

                  It is much better that you don't use CxImage

                  ?!CImage

                  _**


                  **_

                  WhiteSky


                  T Offline
                  T Offline
                  Tcpip2005
                  wrote on last edited by
                  #12

                  void CSaveBmpToFileDlg::GetImageFromList(CImageList *lstImages, CBitmap* destBitmap)
                  {

                  CImageList tmpList;
                  tmpList.Create(lstImages);
                  
                  
                  IMAGEINFO lastImage;
                  tmpList.GetImageInfo(0,&lastImage);
                  
                  CDC dcMem; 
                  
                  dcMem.CreateCompatibleDC(GetWindowDC()); 
                  
                  CRect rect (lastImage.rcImage);
                  
                  destBitmap->CreateCompatibleBitmap (this->GetWindowDC(), 
                  	rect.Width () \* tmpList.GetImageCount(), rect.Height ());
                  
                  CBitmap\* pBmpOld = dcMem.SelectObject (destBitmap);
                  
                  for (int i=0;i
                  

                  I got this code. the bmp itself was nice.but still,the back was black:(

                  H 1 Reply Last reply
                  0
                  • T Tcpip2005

                    void CSaveBmpToFileDlg::GetImageFromList(CImageList *lstImages, CBitmap* destBitmap)
                    {

                    CImageList tmpList;
                    tmpList.Create(lstImages);
                    
                    
                    IMAGEINFO lastImage;
                    tmpList.GetImageInfo(0,&lastImage);
                    
                    CDC dcMem; 
                    
                    dcMem.CreateCompatibleDC(GetWindowDC()); 
                    
                    CRect rect (lastImage.rcImage);
                    
                    destBitmap->CreateCompatibleBitmap (this->GetWindowDC(), 
                    	rect.Width () \* tmpList.GetImageCount(), rect.Height ());
                    
                    CBitmap\* pBmpOld = dcMem.SelectObject (destBitmap);
                    
                    for (int i=0;i
                    

                    I got this code. the bmp itself was nice.but still,the back was black:(

                    H Offline
                    H Offline
                    Hamid Taebi
                    wrote on last edited by
                    #13

                    In this example we have a 32x32 and if you calculate x for x for draw function then your problem solve but if you want to get x& y from icons in CImageList see ImageList_GetIconSize(yourlist,x,y) and then insert x to current position in DrawIcon if you test this code and your problem is slove i glad but if you have previous error reply to me:)

                    _**


                    **_

                    WhiteSky


                    T 1 Reply Last reply
                    0
                    • H Hamid Taebi

                      In this example we have a 32x32 and if you calculate x for x for draw function then your problem solve but if you want to get x& y from icons in CImageList see ImageList_GetIconSize(yourlist,x,y) and then insert x to current position in DrawIcon if you test this code and your problem is slove i glad but if you have previous error reply to me:)

                      _**


                      **_

                      WhiteSky


                      T Offline
                      T Offline
                      Tcpip2005
                      wrote on last edited by
                      #14

                      Thank you sir. I tried to do as what you have said. the bmp file was saved correctly. but the background was still black. I want to change the background into RGB(255,0,255). How could I do so? Thank you very much.

                      H 1 Reply Last reply
                      0
                      • T Tcpip2005

                        Thank you sir. I tried to do as what you have said. the bmp file was saved correctly. but the background was still black. I want to change the background into RGB(255,0,255). How could I do so? Thank you very much.

                        H Offline
                        H Offline
                        Hamid Taebi
                        wrote on last edited by
                        #15

                        for black background dc.DrawIcon(x/*32*/, 0, m_ImageList->ExtractIcon(i)); i used 32x32 for your icons you need to calculate x and y for change background you can use from: you need to two CDC objects one for draw icon and another for draw previous dc in new dc(for change color) 1-create two dc(dc1,dc2)and create two bitmap 2-in dc1 you draw icon 3-in dc2 you need to set color for bitmap and draw dc1 to dc2 4-then save this dc it seems that its hard but when you start to this work its not hard also you can find examples for this purpose in bitmap i think i see examples for example you need to draw many pictures to a picture if you write this program then its very helpful in your programming.

                        _**


                        **_

                        WhiteSky


                        M 1 Reply Last reply
                        0
                        • H Hamid Taebi

                          for black background dc.DrawIcon(x/*32*/, 0, m_ImageList->ExtractIcon(i)); i used 32x32 for your icons you need to calculate x and y for change background you can use from: you need to two CDC objects one for draw icon and another for draw previous dc in new dc(for change color) 1-create two dc(dc1,dc2)and create two bitmap 2-in dc1 you draw icon 3-in dc2 you need to set color for bitmap and draw dc1 to dc2 4-then save this dc it seems that its hard but when you start to this work its not hard also you can find examples for this purpose in bitmap i think i see examples for example you need to draw many pictures to a picture if you write this program then its very helpful in your programming.

                          _**


                          **_

                          WhiteSky


                          M Offline
                          M Offline
                          mathievp
                          wrote on last edited by
                          #16

                          You can try this HBRUSH hbr; hbr = ::CreateSolidBrush(RGB(255,255,255)); //this will draw white BackGround before drawing ICON onto it. DrawIconEx(hDC,0,0,hIcon,0,0,0,hbr,DI_DEFAULTSIZE); Matt

                          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