Advertisement

03.05.2008 at 12:39AM PST, ID: 23215272
[x]
Attachment Details

Converting Bitmap in 2D Array

Asked by andy06 in Microsoft Visual C++, Microsoft Visual C#.Net, Signal Processing

Tags: C++, image processing,bitmap,Win32 API

Hi everyone ,
I'm doing image processing for the first time and I'm working with VC++ 6.0 under WinXP.
I would like to create a function which loads an 8 bit grayscale bitmap image and convert it
into a 2D array where each element represents one of the image's
pixel intensities for further purposes e.g. to calculate the fft.I saw quite similar
examples on this homepage but none of them returns an 2D array.
My code is attached in Code Snippet
The problem is that I would like to have the values of the array returned and I don't know how it should look like inside LRESULT CALLBACK WndProc function(I'm using Win32 API).And I'm also getting error message because of following declarations:
BYTE  tempScanLine[WIDTH * 1]  // error C2057:it should be a constant expression
                                                    //error C2466 : can't reserved an array of size 0
                                                 //  error C2133: 'tempScanLine' : unknown parameter
const double grayscale[WIDTH*HEIGHT]; //  error C2133: 'grayscale' : unknown parameter
I thought of writing grayscale=new double [WIDTH*HEIGHT] but then I have to give the memory free
and I can't return the array anymore right?
Thank youStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{	
static HBITMAP hbitmap;
int WIDTH, HEIGHT;
switch (message)
     {
   case WM_PAINT:
				
HANDLE hObj = LoadImage(NULL,"image.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
HDC hdc = CreateCompatibleDC(NULL);
SelectObject(hdc, hObj);
BITMAPINFO bInfo;
bInfo.bmiHeader.biSize = sizeof(bInfo.bmiHeader);
bInfo.bmiHeader.biWidth = WIDTH;
bInfo.bmiHeader.biHeight = HEIGHT;
bInfo.bmiHeader.biPlanes = 1;
bInfo.bmiHeader.biBitCount = 8; 
bInfo.bmiHeader.biCompression = BI_RGB;
BYTE tempScanLine[WIDTH ];
BYTE info[HEIGHT][WIDTH][1];
BITMAPINFO bi;
ZeroMemory(&bi, sizeof(BITMAPINFO));
bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
int count = HEIGHT - 1;
const double grayscale[WIDTH*HEIGHT];
for(int j = 0; j < HEIGHT; ++j)
{
      // find the width of the object
      GetDIBits(hdc, (HBITMAP) hObj, j, 1, NULL, &bi, DIB_RGB_COLORS);
 
      // store the color values in a 3D array of bytes
      GetDIBits(hdc, (HBITMAP) hObj, j, 1, tempScanLine, &bInfo, DIB_RGB_COLORS);
      for(int z = 0; z < bi.bmiHeader.biWidth; ++z)
      {
            info[count][z][0] = tempScanLine[(z * 1) + 2];    
            info[count][z][1] = tempScanLine[(z * 1) + 1];     
            info[count][z][2] = tempScanLine[(z * 1) + 0];                   
          //Transform to gray values
            grayscale[z]=info[count][z][0]*0.299 + info[count][z][1]*0.587+info[count][z][2]*0.114;
      }
     --count;
}
 
 
[+][-]03.05.2008 at 09:37AM PST, ID: 21052467

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.05.2008 at 09:58AM PST, ID: 21052688

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.05.2008 at 10:42PM PST, ID: 21057906

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.06.2008 at 05:42AM PST, ID: 21060005

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.08.2008 at 02:35PM PST, ID: 21078952

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.12.2008 at 10:40AM PDT, ID: 21108651

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.12.2008 at 11:52PM PDT, ID: 21113858

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.13.2008 at 02:48AM PDT, ID: 21114492

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.13.2008 at 07:51PM PDT, ID: 21122712

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.17.2008 at 02:19AM PDT, ID: 21140652

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.17.2008 at 04:22PM PDT, ID: 21147293

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.18.2008 at 07:46AM PDT, ID: 21151575

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.19.2008 at 05:44AM PDT, ID: 21160861

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.19.2008 at 02:00PM PDT, ID: 21165849

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.31.2008 at 05:32AM PDT, ID: 21244741

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.31.2008 at 07:14AM PDT, ID: 21245520

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.31.2008 at 12:35PM PDT, ID: 21248374

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.01.2008 at 01:38AM PDT, ID: 21252177

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.01.2008 at 08:20PM PDT, ID: 21259968

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Visual C++, Microsoft Visual C#.Net, Signal Processing
Tags: C++, image processing,bitmap,Win32 API
Sign Up Now!
Solution Provided By: DanRollins
Participating Experts: 2
Solution Grade: A
 
 
[+][-]04.02.2008 at 07:45AM PDT, ID: 21263573

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628