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. what happened when CImage load a 16-bit BMP file

what happened when CImage load a 16-bit BMP file

Scheduled Pinned Locked Moved C / C++ / MFC
htmlhelpquestion
11 Posts 2 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.
  • F Offline
    F Offline
    fitatc
    wrote on last edited by
    #1

    I am try to deal with 16-bit bmp file with CImage class. but when I load a 16-bit bmp file with CImage::load(LPCTSTR pszFileName) and get bits-per-pixel value by CImage::GetBPP, the return is 32:confused:.

    CImage imgOriginal;
    hResult = imgOriginal.Load(m_FileName);
    if(FAILED(hResult)){
    // hanle error
    }

    int iBpp = imgOriginal.GetBPP();

    I am using VS2008 in Windows Xp. I can not find any comment about this from msdn, Could anyone tell me what happened in CImage::Load? for a 16-bit bmp sample file, see : http://wvnvaxa.wvnet.edu/vmswww/bmp.html[^]

    M 1 Reply Last reply
    0
    • F fitatc

      I am try to deal with 16-bit bmp file with CImage class. but when I load a 16-bit bmp file with CImage::load(LPCTSTR pszFileName) and get bits-per-pixel value by CImage::GetBPP, the return is 32:confused:.

      CImage imgOriginal;
      hResult = imgOriginal.Load(m_FileName);
      if(FAILED(hResult)){
      // hanle error
      }

      int iBpp = imgOriginal.GetBPP();

      I am using VS2008 in Windows Xp. I can not find any comment about this from msdn, Could anyone tell me what happened in CImage::Load? for a 16-bit bmp sample file, see : http://wvnvaxa.wvnet.edu/vmswww/bmp.html[^]

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

      iBpp is 16 for me. Mark

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

      F 1 Reply Last reply
      0
      • M Mark Salsbery

        iBpp is 16 for me. Mark

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

        F Offline
        F Offline
        fitatc
        wrote on last edited by
        #3

        Thanks very much for answer my qustion. 1.Did you test in windows xp? I tryed it again, and is still 32. 2.And I finded another stranged thing: If I right click that sample 16-bit bmp file to see it's property, It's 32 too. :omg: Maybe this two things is connected, And if your OS not show 32-bit, That could be my OS problem.

        M 1 Reply Last reply
        0
        • F fitatc

          Thanks very much for answer my qustion. 1.Did you test in windows xp? I tryed it again, and is still 32. 2.And I finded another stranged thing: If I right click that sample 16-bit bmp file to see it's property, It's 32 too. :omg: Maybe this two things is connected, And if your OS not show 32-bit, That could be my OS problem.

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

          fitatc wrote:

          1.Did you test in windows xp? I tryed it again, and is still 32.

          I first tested only on Vista Ultimate SP1. This morning I tested on XP Pro SP3...same result... 16bpp

          fitatc wrote:

          2.And I finded another stranged thing: If I right click that sample 16-bit bmp file to see it's property, It's 32 too.

          Are you sure you downloaded the right file? I right-clicked the 16bit sample from the link and saved it to my harddrive to test. Mark

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

          F 1 Reply Last reply
          0
          • M Mark Salsbery

            fitatc wrote:

            1.Did you test in windows xp? I tryed it again, and is still 32.

            I first tested only on Vista Ultimate SP1. This morning I tested on XP Pro SP3...same result... 16bpp

            fitatc wrote:

            2.And I finded another stranged thing: If I right click that sample 16-bit bmp file to see it's property, It's 32 too.

            Are you sure you downloaded the right file? I right-clicked the 16bit sample from the link and saved it to my harddrive to test. Mark

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

            F Offline
            F Offline
            fitatc
            wrote on last edited by
            #5

            // --- file's property --- //

            Mark Salsbery wrote:

            Are you sure you downloaded the right file? I right-clicked the 16bit sample from the link and saved it to my harddrive to test.

            Yes, I check it by Read it in Hex, it's 16.

            42 4D 42 40 00 00 00 00 00 00 42 00 00 00 28
            00 00 00 7F 00 00 00 40 00 00 00 01 00 10 00
            03 00 00 00 00 40 00 00 00 00 00 00 00 00 00
            ...

            but, In my OS, the file property is still 32. I think it's may be my OS's problem, XP-Professional Version 2002 Service Pack 2. And since I works in japan, my OS is janpanese version of WindowsXP. // --- CImage --- // Others in MSDN forum advised me not to use CImage, because it's for display. And I find that I can't get "the type of compression" by CImage class, :confused:So, is it possible that Cimage class change the "BI_BITFIELDS compressed 16-bit bmp" to "uncompressed 32-bit bmp" in CImage::load?

            M 1 Reply Last reply
            0
            • F fitatc

              // --- file's property --- //

              Mark Salsbery wrote:

              Are you sure you downloaded the right file? I right-clicked the 16bit sample from the link and saved it to my harddrive to test.

              Yes, I check it by Read it in Hex, it's 16.

              42 4D 42 40 00 00 00 00 00 00 42 00 00 00 28
              00 00 00 7F 00 00 00 40 00 00 00 01 00 10 00
              03 00 00 00 00 40 00 00 00 00 00 00 00 00 00
              ...

              but, In my OS, the file property is still 32. I think it's may be my OS's problem, XP-Professional Version 2002 Service Pack 2. And since I works in japan, my OS is janpanese version of WindowsXP. // --- CImage --- // Others in MSDN forum advised me not to use CImage, because it's for display. And I find that I can't get "the type of compression" by CImage class, :confused:So, is it possible that Cimage class change the "BI_BITFIELDS compressed 16-bit bmp" to "uncompressed 32-bit bmp" in CImage::load?

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

              fitatc wrote:

              Others in MSDN forum advised me not to use CImage

              CImage just wraps a DIBSection and uses GDI+ for loading and saving images. If that's what you need it can be used for anything DIBsection-related, not just for display.

              fitatc wrote:

              is it possible that Cimage class change the "BI_BITFIELDS compressed 16-bit bmp" to "uncompressed 32-bit bmp" in CImage::load?

              It's possible, but I don't know why it would be changed. Run it in the debugger and step into the CImage::Load() code. I did, and it looks like it is possible (in CImage::CreateFromGdiplusBitmap()) to be converted to a 32bpp bitmap but that code is bypassed. This shouldn't be OS related - GDI+ didn't change for years before Vista. It could be the version of CImage you're using however. What Visual Studio version are you using? Step into the code - it doesn't change magically :) Mark

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

              F 1 Reply Last reply
              0
              • M Mark Salsbery

                fitatc wrote:

                Others in MSDN forum advised me not to use CImage

                CImage just wraps a DIBSection and uses GDI+ for loading and saving images. If that's what you need it can be used for anything DIBsection-related, not just for display.

                fitatc wrote:

                is it possible that Cimage class change the "BI_BITFIELDS compressed 16-bit bmp" to "uncompressed 32-bit bmp" in CImage::load?

                It's possible, but I don't know why it would be changed. Run it in the debugger and step into the CImage::Load() code. I did, and it looks like it is possible (in CImage::CreateFromGdiplusBitmap()) to be converted to a 32bpp bitmap but that code is bypassed. This shouldn't be OS related - GDI+ didn't change for years before Vista. It could be the version of CImage you're using however. What Visual Studio version are you using? Step into the code - it doesn't change magically :) Mark

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

                F Offline
                F Offline
                fitatc
                wrote on last edited by
                #7

                Mark Salsbery wrote:

                It could be the version of CImage you're using however. What Visual Studio version are you using?

                My visual Studio version is: 2008, Version 9.0.21022.0 RTM. I steped into the code, as your said, It seems like the point is in

                Bitmap::Bitmap(
                IN const WCHAR *filename,
                IN BOOL useEmbeddedColorManagement
                )
                {
                ...
                lastResult = DllExports::GdipCreateBitmapFromFile(filename, &bitmap);
                }

                ;P but I am not very familiar with GDI+, so I determined to study it for my question. Thanks very much for your help, and I know how I can deal with the question like this now. :)

                M 1 Reply Last reply
                0
                • F fitatc

                  Mark Salsbery wrote:

                  It could be the version of CImage you're using however. What Visual Studio version are you using?

                  My visual Studio version is: 2008, Version 9.0.21022.0 RTM. I steped into the code, as your said, It seems like the point is in

                  Bitmap::Bitmap(
                  IN const WCHAR *filename,
                  IN BOOL useEmbeddedColorManagement
                  )
                  {
                  ...
                  lastResult = DllExports::GdipCreateBitmapFromFile(filename, &bitmap);
                  }

                  ;P but I am not very familiar with GDI+, so I determined to study it for my question. Thanks very much for your help, and I know how I can deal with the question like this now. :)

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

                  fitatc wrote:

                  Bitmap::Bitmap

                  What is this? I thought you were using CImage? :)

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

                  F 1 Reply Last reply
                  0
                  • M Mark Salsbery

                    fitatc wrote:

                    Bitmap::Bitmap

                    What is this? I thought you were using CImage? :)

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

                    F Offline
                    F Offline
                    fitatc
                    wrote on last edited by
                    #9

                    Mark Salsbery wrote:

                    What is this? I thought you were using CImage?

                    Yes, I just steped into the CImage::Load() It's like below:

                    atlimage.h
                    inline HRESULT CImage::Load( LPCTSTR pszFileName ) throw()
                    {
                    if( !InitGDIPlus() )
                    {
                    return( E_FAIL );
                    }

                    Gdiplus::Bitmap bmSrc( (CT2W)pszFileName );      ---- ★
                    if( bmSrc.GetLastStatus() != Gdiplus::Ok )
                    {
                    	return( E\_FAIL );
                    }
                    
                    return( CreateFromGdiplusBitmap( bmSrc ) );
                    

                    }

                    I steped into ★, because all the BMP data it's used below is from here, and I get:

                    inline
                    Bitmap::Bitmap(
                    IN const WCHAR *filename,
                    IN BOOL useEmbeddedColorManagement
                    )
                    {
                    GpBitmap *bitmap = NULL;

                    if(useEmbeddedColorManagement) 
                    {
                        lastResult = DllExports::GdipCreateBitmapFromFileICM(filename, &bitmap);
                    }
                    else
                    {
                        lastResult = DllExports::GdipCreateBitmapFromFile(filename, &bitmap);   --- ★★
                    }
                    
                    SetNativeImage(bitmap);
                    

                    }

                    :-D ★★:this is what I posted in last time, sorry for confusing message.

                    M 2 Replies Last reply
                    0
                    • F fitatc

                      Mark Salsbery wrote:

                      What is this? I thought you were using CImage?

                      Yes, I just steped into the CImage::Load() It's like below:

                      atlimage.h
                      inline HRESULT CImage::Load( LPCTSTR pszFileName ) throw()
                      {
                      if( !InitGDIPlus() )
                      {
                      return( E_FAIL );
                      }

                      Gdiplus::Bitmap bmSrc( (CT2W)pszFileName );      ---- ★
                      if( bmSrc.GetLastStatus() != Gdiplus::Ok )
                      {
                      	return( E\_FAIL );
                      }
                      
                      return( CreateFromGdiplusBitmap( bmSrc ) );
                      

                      }

                      I steped into ★, because all the BMP data it's used below is from here, and I get:

                      inline
                      Bitmap::Bitmap(
                      IN const WCHAR *filename,
                      IN BOOL useEmbeddedColorManagement
                      )
                      {
                      GpBitmap *bitmap = NULL;

                      if(useEmbeddedColorManagement) 
                      {
                          lastResult = DllExports::GdipCreateBitmapFromFileICM(filename, &bitmap);
                      }
                      else
                      {
                          lastResult = DllExports::GdipCreateBitmapFromFile(filename, &bitmap);   --- ★★
                      }
                      
                      SetNativeImage(bitmap);
                      

                      }

                      :-D ★★:this is what I posted in last time, sorry for confusing message.

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

                      Oh it was Gdiplus::Bitmap :) Anyway, CreateFromGdiplusBitmap() is the method you want to step into. That's the one that may change the format to 32bpp, but it doesn't for me. Mark

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

                      1 Reply Last reply
                      0
                      • F fitatc

                        Mark Salsbery wrote:

                        What is this? I thought you were using CImage?

                        Yes, I just steped into the CImage::Load() It's like below:

                        atlimage.h
                        inline HRESULT CImage::Load( LPCTSTR pszFileName ) throw()
                        {
                        if( !InitGDIPlus() )
                        {
                        return( E_FAIL );
                        }

                        Gdiplus::Bitmap bmSrc( (CT2W)pszFileName );      ---- ★
                        if( bmSrc.GetLastStatus() != Gdiplus::Ok )
                        {
                        	return( E\_FAIL );
                        }
                        
                        return( CreateFromGdiplusBitmap( bmSrc ) );
                        

                        }

                        I steped into ★, because all the BMP data it's used below is from here, and I get:

                        inline
                        Bitmap::Bitmap(
                        IN const WCHAR *filename,
                        IN BOOL useEmbeddedColorManagement
                        )
                        {
                        GpBitmap *bitmap = NULL;

                        if(useEmbeddedColorManagement) 
                        {
                            lastResult = DllExports::GdipCreateBitmapFromFileICM(filename, &bitmap);
                        }
                        else
                        {
                            lastResult = DllExports::GdipCreateBitmapFromFile(filename, &bitmap);   --- ★★
                        }
                        
                        SetNativeImage(bitmap);
                        

                        }

                        :-D ★★:this is what I posted in last time, sorry for confusing message.

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

                        Also, if after stepping into the CImage loader code you find it does't do what you want, it's pretty easy to load BMP files yourself - much easier than other file formats with complicated compression. Mark

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

                        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