Solved

Reading bmp resource file into RGBQUAD array.

Posted on 2002-07-17
5
973 Views
Last Modified: 2008-03-03
Hi.

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;
}

0
Comment
Question by:Itzike
5 Comments
 
LVL 8

Accepted Solution

by:
fl0yd earned 50 total points
ID: 7160760
The bmiColors[]-member is only used for biBitCount <= 8 -- it is a color palette, not to be confused with the actual bitmap data.
0
 

Author Comment

by:Itzike
ID: 7161428
So how can I get the bitmap data in to bytes array?
0
 
LVL 12

Expert Comment

by:pjknibbs
ID: 7161437
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;
} BITMAPFILEHEADER, *PBITMAPFILEHEADER;

(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).
0
 
LVL 11

Expert Comment

by:griessh
ID: 7376086
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.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 6

Expert Comment

by:Mindphaser
ID: 7419912
Force accepted

** Mindphaser - Community Support Moderator **

pjknibbs, there will be a separate question with points for your help.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now