?
Solved

Reading bmp resource file into RGBQUAD array.

Posted on 2002-07-17
5
Medium Priority
?
1,033 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 200 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

755 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