Reading bmp resource file into RGBQUAD array.


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] .rgbBlue,
bmiColor[i] .rgbGreen,
bmiColor[i] .rgbRed and
bmiColor[i] .rgbReserved

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)
HRSRC hRsrc;
if( hRsrc = FindResource( hCurInst, MAKEINTRESOURCE lIDB),
                                              RT_BITMAP) )
   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]=m_bmpData ->bmciColors[i].rgbRed;
  m_Image[4*i+1]=m_bmpData ->bmciColors[i].rgbGreen;
  m_Image[4*i+2]= m_bmpData ->bmciColors[i].rgbBlue;
  m_Image[4*i+3] = 1;

Who is Participating?
fl0ydConnect With a Mentor Commented:
The bmiColors[]-member is only used for biBitCount <= 8 -- it is a color palette, not to be confused with the actual bitmap data.
ItzikeAuthor Commented:
So how can I get the bitmap data in to bytes array?
It already IS in a byte array--if you load the bitmap directly from a file on disk into memory, the first few bytes are a BITMAPFILEHEADER structure like this:

typedef struct tagBITMAPFILEHEADER {
  WORD    bfType;
  DWORD   bfSize;
  WORD    bfReserved1;
  WORD    bfReserved2;
  DWORD   bfOffBits;

(This is defined in the Windows header files somewhere). Anyway, the bfOffBits member tells you the offset from the beginning of the file to where the raw bitmap data is stored. (The BITMAPINFO structure immediately follows the BITMAPFILEHEADER, should you need to extract colour depth information, palettes, or what-have-you).
Dear Itzike

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to split between

     "fl0yd and pjknibbs"

comment(s) as an answer.

Force accepted

** Mindphaser - Community Support Moderator **

pjknibbs, there will be a separate question with points for your help.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.