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 is order of colors in bitmap pixel array?

What is order of colors in bitmap pixel array?

Scheduled Pinned Locked Moved C / C++ / MFC
questiongraphicsdata-structures
7 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.
  • V Offline
    V Offline
    vgrigor
    wrote on last edited by
    #1

    I created red bimap,(0000FF) get it's pixels by following code, but method showes pixels is blue (FF0000): How order of colors and bytes myst be read to make getting color and place of pixel correct? BITMAP bm ; DWORD* pBits; GetObject(hBitmap, sizeof(BITMAP), &bm); pBits= new DWORD[bm.bmHeight*bm.bmWidth]; memset(pBits, bm.bmHeight*bm.bmWidth ,0); GetBitmapBits( hBitmap, (bm.bmHeight*bm.bmWidth*4), pBits ); COLORREF* pCr; int bt_cr = bm.bmBitsPixel/8; //bytes per color for(int h =0; h < bm.bmHeight; h++) for(int w =0; w < bm.bmWidth; w++) { pCr = (COLORREF*) & ((BYTE*)/*bm.bmBits*/pBits)[ w* bt_cr + h*bm.bmWidthBytes ]; // =FF0000 BYTE pureR,pureG,pureB; pureR =GetRValue(*pCr); // =0 - result pureG =GetGValue(*pCr); // =0 pureB =GetBValue(*pCr); // =255

    B 1 Reply Last reply
    0
    • V vgrigor

      I created red bimap,(0000FF) get it's pixels by following code, but method showes pixels is blue (FF0000): How order of colors and bytes myst be read to make getting color and place of pixel correct? BITMAP bm ; DWORD* pBits; GetObject(hBitmap, sizeof(BITMAP), &bm); pBits= new DWORD[bm.bmHeight*bm.bmWidth]; memset(pBits, bm.bmHeight*bm.bmWidth ,0); GetBitmapBits( hBitmap, (bm.bmHeight*bm.bmWidth*4), pBits ); COLORREF* pCr; int bt_cr = bm.bmBitsPixel/8; //bytes per color for(int h =0; h < bm.bmHeight; h++) for(int w =0; w < bm.bmWidth; w++) { pCr = (COLORREF*) & ((BYTE*)/*bm.bmBits*/pBits)[ w* bt_cr + h*bm.bmWidthBytes ]; // =FF0000 BYTE pureR,pureG,pureB; pureR =GetRValue(*pCr); // =0 - result pureG =GetGValue(*pCr); // =0 pureB =GetBValue(*pCr); // =255

      B Offline
      B Offline
      Babayan Hovhannes
      wrote on last edited by
      #2

      Each pixel has BGR format. I know this from bitmap displaying in OpenGL. yiy

      V 1 Reply Last reply
      0
      • B Babayan Hovhannes

        Each pixel has BGR format. I know this from bitmap displaying in OpenGL. yiy

        V Offline
        V Offline
        vgrigor
        wrote on last edited by
        #3

        Right answer is: to a 32 bit dib, the order is XRGB. to a 24 bit dib, the order is BGR. But to a 16 bit dib, there are two types. X555, 565. I don't know which one is correct or which one should be by given a dib. Maybe who can tell me. http://www.codeguru.com/forum/showthread.php?s=&postid=799709#post799709

        B R 2 Replies Last reply
        0
        • V vgrigor

          Right answer is: to a 32 bit dib, the order is XRGB. to a 24 bit dib, the order is BGR. But to a 16 bit dib, there are two types. X555, 565. I don't know which one is correct or which one should be by given a dib. Maybe who can tell me. http://www.codeguru.com/forum/showthread.php?s=&postid=799709#post799709

          B Offline
          B Offline
          Babayan Hovhannes
          wrote on last edited by
          #4

          Each pixel is COLORREF value. sizeof(COLORREF) is 24. 24/3=8. It means, that you can describe each pixel with three 8-bit values. So, naturally, you have only 24-bit dib in bitmap pixel array. And it is true. yiy

          1 Reply Last reply
          0
          • V vgrigor

            Right answer is: to a 32 bit dib, the order is XRGB. to a 24 bit dib, the order is BGR. But to a 16 bit dib, there are two types. X555, 565. I don't know which one is correct or which one should be by given a dib. Maybe who can tell me. http://www.codeguru.com/forum/showthread.php?s=&postid=799709#post799709

            R Offline
            R Offline
            roel_
            wrote on last edited by
            #5

            8-bit and 16-bit dibs are indexed, they are not rgb values. Read all about them in the Petzold.

            V 1 Reply Last reply
            0
            • R roel_

              8-bit and 16-bit dibs are indexed, they are not rgb values. Read all about them in the Petzold.

              V Offline
              V Offline
              vgrigor
              wrote on last edited by
              #6

              I do not works with DIB, just need correctly proceed 24 and 32 bit BITMAPS only. Do you think despite all samples did for bitmap, DIB much better dor speed and suitability?

              R 1 Reply Last reply
              0
              • V vgrigor

                I do not works with DIB, just need correctly proceed 24 and 32 bit BITMAPS only. Do you think despite all samples did for bitmap, DIB much better dor speed and suitability?

                R Offline
                R Offline
                roel_
                wrote on last edited by
                #7

                just need correctly proceed 24 and 32 bit BITMAPS only.
                Well yeah but you mentioned 16-bit bitmaps so I figured I'd correct that...
                As for ddb vs dib, I find it easier to work with ddb's (they're faster too) but when you have a very large bitmap you may run out of video memory... It all depends on your application, basically.

                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