Solved

Reading bmp resource file into RGBQUAD array.

Posted on 2002-07-17
5
982 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

832 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