What is order of colors in bitmap pixel array?
-
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
-
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
Each pixel has BGR format. I know this from bitmap displaying in OpenGL. yiy
-
Each pixel has BGR format. I know this from bitmap displaying in OpenGL. yiy
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
-
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
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
-
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
-
8-bit and 16-bit dibs are indexed, they are not rgb values. Read all about them in the Petzold.
-
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?
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.