PDA

View Full Version : Save RGB-Values in 2D-Array



Tobias
February 21, 2009, 12:41:08
Hello I have a Problem with extracting the RGB-Values in 2D-Arrays. I have 3 Arrays R[480][640], G[480][640] and B[480][640].

Now I get the Pointer of my Image-Buffer and want to save the R-,G-,B-Value in my Arrays for each Pixel.

I wrote something like this:

for (int i = 0; i< MAX_ROW; i++)
{
for (int j = 0; j< MAX_COLUMN; j++)
{
B[i][j] = bTmpArray[j+i*MAX_COLUMN*3];
G[i][j] = bTmpArray[j+i*MAX_COLUMN*3+1];
R[i][j] = bTmpArray[j+i*MAX_COLUMN*3+2];
}
}

The Result of my Function is not as expected, so I saved the Image and did the same function with another Demo-Application, which uses Bitmap-Functions to fill the arrays and there ist works.

The second problem is, when I want to show my buffer in the application, I copy back the values of my arrays in an Image-Buffer Array, it looks like:

for (int i = 0; i< MAX_ROW; i++)
{
for (int j = 0; j< MAX_COLUMN; j++)
{
bTmpArray[j+i*MAX_COLUMN*3] = 0/*0 for test, normaly B[i][j]*/;
bTmpArray[j+i*MAX_COLUMN*3+1] = 0 /*0 for test, normaly G[i][j]*/;
bTmpArray[j+i*MAX_COLUMN*3+2] = 0 /*0 for test, normaly R[i][j]*/;
}
}
The result is, that only 1/3 of picture is black, the other 2/3 the original Image is shown.

Does anybody what Im doing wrong?

Thank you

Tobias
February 22, 2009, 07:41:43
Ok, sometimes its better to make a break and go back to work a little bit later.

The solution was very simple after I looked at the problem this morning:

bTmpArray[(columns+row*Max_column) *3];

That was all I forget....

Thanks

Stefan Geissler
February 23, 2009, 08:45:17
Tobias,

I am glad you solved your problem.