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. Why can't it show a whole bitmap in listctrl in icon form

Why can't it show a whole bitmap in listctrl in icon form

Scheduled Pinned Locked Moved C / C++ / MFC
graphicstutorialquestionlearning
21 Posts 5 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.
  • J James R Twine

    Actually, you need that parameter for masks to work correctly even in 8-bit images.  For any images with a higher bit depth, I have had too much trouble trying to get mixed colors exactly right for that to work correctly for me.  Couple that with art software that does dithering (with higher depth images) when not asked to and the problem gets real bad real quick.     Was easier to just build a mask bitmap and set it directly in the control.    Peace!

    -=- James
    Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
    Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
    See DeleteFXPFiles

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

    James R. Twine wrote:

    I have had too much trouble trying to get mixed colors exactly right for that to work correctly for me. Couple that with art software that does dithering (with higher depth images) when not asked to and the problem gets real bad real quick.

    :-D That's when I'd hand the problem off to the art department (ie, my graphic-designer girlfriend LOL). There's 16777216 colors...how hard can it be to find ONE to use as a transparent color? :laugh: Cheers!

    "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

    1 Reply Last reply
    0
    • J James R Twine

      You can use some software, like MSPaint, or the GIMP[^], to scale the images outside of the application.  If you need to scale it internally, you can use GDI/GDI+ to draw the bitmap scaled directly into the appropriate area of the Imagelist control.    This is a bit tricky if you have a large number of images.  Basically, you preallocate the space for the images in the Imagelist control using the ImageList_SetImageCount(...) macro, extract IMAGEINFO structures for each image "space" using the ImageList_GetImageInfo(...) macro, and then drawing the scaled-down image directly into the IMAGEINFO::hbmImage bitmap area.    Got all that?   :P    Also, the "mask" is a color (or an area of the image) that is considered transparent when the image is drawn.  In other words, the "mask" color (or area) is not drawn when the image is drawn onto the control.    Peace!

      -=- James
      Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
      Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
      See DeleteFXPFiles

      C Offline
      C Offline
      Chen XuNuo
      wrote on last edited by
      #13

      Thanks~ But I am confused that I don't know how to resize the bitmaps before insert them to imagelist,is there any fuctions to do this? And I have refer to the example http://www.codeproject.com/listctrl/thumbnail.asp?df=100&forumid=1951&fr=51[^] in cp.I found it do nothing to resize the bitmaps,but they are automaticly showed in thumbnails.Why`:confused:

      James R. Twine wrote:

      extract IMAGEINFO structures for each image "space" using the ImageList_GetImageInfo(...) macro, and then drawing the scaled-down image directly into the IMAGEINFO::hbmImage bitmap area.

      What is the purpose of this?I can only get the information in imagelist through this.And if I change the IMAGEINFO what I get from it ,nothing changed. X|

      J 1 Reply Last reply
      0
      • C Chen XuNuo

        Thanks~ But I am confused that I don't know how to resize the bitmaps before insert them to imagelist,is there any fuctions to do this? And I have refer to the example http://www.codeproject.com/listctrl/thumbnail.asp?df=100&forumid=1951&fr=51[^] in cp.I found it do nothing to resize the bitmaps,but they are automaticly showed in thumbnails.Why`:confused:

        James R. Twine wrote:

        extract IMAGEINFO structures for each image "space" using the ImageList_GetImageInfo(...) macro, and then drawing the scaled-down image directly into the IMAGEINFO::hbmImage bitmap area.

        What is the purpose of this?I can only get the information in imagelist through this.And if I change the IMAGEINFO what I get from it ,nothing changed. X|

        J Offline
        J Offline
        James R Twine
        wrote on last edited by
        #14

        You need to look at the code for that project before asking...  That project uses GDI+ code to generate the thumbnails and then adds the thumbnails to the imagelist control used by the listview control.

        Bitmap img( A2W(strPath) );
        Bitmap* pThumbnail = static_cast(img.GetThumbnailImage(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, NULL, NULL));
        // attach the thumbnail bitmap handle to an CBitmap object
        pThumbnail->GetHBITMAP(NULL, &hBmp);
        pImage = new CBitmap();
        pImage->Attach(hBmp);
        // add bitmap to our image list
        m_ImageListThumb.Replace(i, pImage, NULL);

        The Bitmap::GetThumbnailImage(...) function scales the image for you returning a new one.    Peace!

        -=- James
        Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
        Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
        See DeleteFXPFiles

        C 3 Replies Last reply
        0
        • J James R Twine

          You need to look at the code for that project before asking...  That project uses GDI+ code to generate the thumbnails and then adds the thumbnails to the imagelist control used by the listview control.

          Bitmap img( A2W(strPath) );
          Bitmap* pThumbnail = static_cast(img.GetThumbnailImage(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, NULL, NULL));
          // attach the thumbnail bitmap handle to an CBitmap object
          pThumbnail->GetHBITMAP(NULL, &hBmp);
          pImage = new CBitmap();
          pImage->Attach(hBmp);
          // add bitmap to our image list
          m_ImageListThumb.Replace(i, pImage, NULL);

          The Bitmap::GetThumbnailImage(...) function scales the image for you returning a new one.    Peace!

          -=- James
          Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
          Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
          See DeleteFXPFiles

          C Offline
          C Offline
          Chen XuNuo
          wrote on last edited by
          #15

          Oh~~~~~~~~~~~~I seldom do the GDI+ and I haven't use the "Bitmap" before.When I do this in my project: HBITMAP hBitmap=LoadBitmap(AfxGetApp()->m_hInstance,MAKEINTRESOURCE(IDB_BITMAP1)); m_imagelist->Create(200,200,ILC_COLOR24|ILC_MASK,1,4); Bitmap img(hBitmap); Bitmap* pThumbnail = static_cast(img.GetThumbnailImage(200, 200, NULL, NULL)); pThumbnail->GetHBITMAP(NULL, &hBitmap); CBitmap bitmap; bitmap.Attach(hBitmap); m_imagelist->SetImageCount(1); m_imagelist->Replace(0,&bitmap,NULL); m_listctrl.SetImageList(m_imagelist,LVSIL_NORMAL); m_listctrl.InsertItem(0,"1",0); There are errors: D:\Code\I Do\ListControl2\ListControl2Dlg.cpp(143) : error C2065: 'Bitmap' : undeclared identifier D:\Code\I Do\ListControl2\ListControl2Dlg.cpp(143) : error C2146: syntax error : missing ';' before identifier 'img' D:\Code\I Do\ListControl2\ListControl2Dlg.cpp(143) : error C2065: 'img' : undeclared identifier D:\Code\I Do\ListControl2\ListControl2Dlg.cpp(144) : error C2065: 'pThumbnail' : undeclared identifier D:\Code\I Do\ListControl2\ListControl2Dlg.cpp(144) : error C2061: syntax error : identifier 'Bitmap' pThumbnail->GetHBITMAP(NULL, &hBitmap); :sigh:

          1 Reply Last reply
          0
          • J James R Twine

            You need to look at the code for that project before asking...  That project uses GDI+ code to generate the thumbnails and then adds the thumbnails to the imagelist control used by the listview control.

            Bitmap img( A2W(strPath) );
            Bitmap* pThumbnail = static_cast(img.GetThumbnailImage(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, NULL, NULL));
            // attach the thumbnail bitmap handle to an CBitmap object
            pThumbnail->GetHBITMAP(NULL, &hBmp);
            pImage = new CBitmap();
            pImage->Attach(hBmp);
            // add bitmap to our image list
            m_ImageListThumb.Replace(i, pImage, NULL);

            The Bitmap::GetThumbnailImage(...) function scales the image for you returning a new one.    Peace!

            -=- James
            Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
            Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
            See DeleteFXPFiles

            C Offline
            C Offline
            Chen XuNuo
            wrote on last edited by
            #16

            Maybe I should include the head file gdiplus.h` Do you have it?Please send to my email~ Thanks~

            1 Reply Last reply
            0
            • J James R Twine

              You need to look at the code for that project before asking...  That project uses GDI+ code to generate the thumbnails and then adds the thumbnails to the imagelist control used by the listview control.

              Bitmap img( A2W(strPath) );
              Bitmap* pThumbnail = static_cast(img.GetThumbnailImage(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, NULL, NULL));
              // attach the thumbnail bitmap handle to an CBitmap object
              pThumbnail->GetHBITMAP(NULL, &hBmp);
              pImage = new CBitmap();
              pImage->Attach(hBmp);
              // add bitmap to our image list
              m_ImageListThumb.Replace(i, pImage, NULL);

              The Bitmap::GetThumbnailImage(...) function scales the image for you returning a new one.    Peace!

              -=- James
              Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
              Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
              See DeleteFXPFiles

              C Offline
              C Offline
              Chen XuNuo
              wrote on last edited by
              #17

              Mm..I have downloaded the gdiplus.h ~But many new errors occur~My god` Basically the errors are about the file gdiplusinit.h~ For example: c:\program files\microsoft visual studio\vc98\include\gdiplusinit.h(39) : error C2065: 'ULONG_PTR' : undeclared identifier

              J 1 Reply Last reply
              0
              • C Chen XuNuo

                Mm..I have downloaded the gdiplus.h ~But many new errors occur~My god` Basically the errors are about the file gdiplusinit.h~ For example: c:\program files\microsoft visual studio\vc98\include\gdiplusinit.h(39) : error C2065: 'ULONG_PTR' : undeclared identifier

                J Offline
                J Offline
                James R Twine
                wrote on last edited by
                #18

                You need to download the entire platform SDK (which may now be called the Windows SDK?), and then install and configure it.    Then you should be able to use GDI+.    Peace!

                -=- James
                Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
                Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
                See DeleteFXPFiles

                C 1 Reply Last reply
                0
                • J James R Twine

                  You need to download the entire platform SDK (which may now be called the Windows SDK?), and then install and configure it.    Then you should be able to use GDI+.    Peace!

                  -=- James
                  Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
                  Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
                  See DeleteFXPFiles

                  C Offline
                  C Offline
                  Chen XuNuo
                  wrote on last edited by
                  #19

                  I have installed it.And I find that GDI+ is a good thing. Do you know how to use Bitmap( Class type, String resource )? Because my bitmap is in the resource,but I don't know how to set the parameter "Class type"~

                  J 1 Reply Last reply
                  0
                  • C Chen XuNuo

                    I have installed it.And I find that GDI+ is a good thing. Do you know how to use Bitmap( Class type, String resource )? Because my bitmap is in the resource,but I don't know how to set the parameter "Class type"~

                    J Offline
                    J Offline
                    James R Twine
                    wrote on last edited by
                    #20

                    You can use the thumbnail project mentioned earlier for examples on how to use some parts of GDI+.    The GDI+ documentation is going to be where you need to go now for more details on how to use it.    Good luck!    Peace!

                    -=- James
                    Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
                    Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
                    See DeleteFXPFiles

                    C 1 Reply Last reply
                    0
                    • J James R Twine

                      You can use the thumbnail project mentioned earlier for examples on how to use some parts of GDI+.    The GDI+ documentation is going to be where you need to go now for more details on how to use it.    Good luck!    Peace!

                      -=- James
                      Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
                      Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
                      See DeleteFXPFiles

                      C Offline
                      C Offline
                      Chen XuNuo
                      wrote on last edited by
                      #21

                      Thanks a lot for helping me so much~:rose:

                      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