Reading bmp resource file into RGBQUAD array.
Posted on 2002-07-17
I have a problem to read a BMP file data into RGB BYTE array.
The BITMAPINFO struct contain RGBQUAD array ‘bmiColor ‘, while I’m trying to load from resource a bitmap to the BITMAPINFO struct, I get the bmiColor points to the resource file as is. Therefore the RGBQUAD become redundant in case of bitmap with only RGB values instead of RGBA values.
If I now try to go with for loop on bmiColor array and get the values
bmiColor[i] .rgbRed and
The values I’ll get is as follow:
bmiColor[i] .rgbBlue = blue value,
bmiColor[i] .rgbGreen = green value,
bmiColor[i] .rgbRed = red value
bmiColor[i] .rgbReserved = the next blue value
bmiColor[i] .rgbBlue = the next green value
bmiColor[i] .rgbGreen = the next red value,
bmiColor[i] .rgbRed = the next blue value
bmiColor[i] .rgbReserved = the next green value and so on.
There is any other simple way to get the bmiColor point to a filled in RGBQUAD array?
My code to load the bitmap from resource is as follow:
void BitmapRes::UpdateBitmapFromResource(HINSTANCE hCurInst, long lIDB)
if( hRsrc = FindResource( hCurInst, MAKEINTRESOURCE lIDB),
HGLOBAL hGlobal = LoadResource( hCurInst, hRsrc ) ;
m_bmpData = (LPBITMAPCOREINFO)LockResource(hGlobal ) ;
UnlockResource( hGlobal );
Then get the values as follow:
unsigned char *m_Image = new unsigned char[size];
for( int i=0; i < size; ++i )
m_Image[4*i+2]= m_bmpData ->bmciColors[i].rgbBlue;
m_Image[4*i+3] = 1;