Solved

Reading bmp resource file into RGBQUAD array.

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

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…
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…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

828 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