Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello..
I have a problem..i want to store a color variable to an array..
Let see my code

C++
Bitmap* bmp = bmp->FromFile(L"coba.bmp", false);
Color color;


and

C++
int i,j;
int width;
int height;
int matriks_gbr[10][10];
width = bmp->GetWidth();
height = bmp->GetHeight();
for (i=0;i<=height-1;i++)
{
	for (j=0;j<=width-1;j++)
	{
		matriks_gbr[i][j] = bmp->GetPixel(i,j,&color);
	}
}


and just wanna to check the content of matriks_gbr :
C++
if (matriks_gbr[0][0] = RGB(255,255,255))
  AfxMessageBox(_T("works"), MB_OK);
else
  AfxMessageBox(_T("not works"), MB_OK);

It worked out (message works) , but when i changed to RGB(255,255,255) to nonzeero number like 255 or 20 , it also appeared "works".
Later i know the problem, getpixel only return Ok and non-ok.
But i want to access the color and store it to an array..
Can you tell me how to store it to array?
Posted
Comments
Simon Bang Terkildsen 8-Sep-11 1:54am    
you have an assignment in your if-statement which I don't beleive you intended, as it'll be false when you assign 0(black) to your array. you should use if (matriks_gbr[0][0] == RGB(255,255,255))

1 solution

GetPixel() you referrig here means API or you have your own.
If its an API, it returns COLORREF.
COLORREF GetPixel(
__in HDC hdc,
__in int nXPos,
__in int nYPos
);

Rather than having the array,
Better have a vector of structures.
In each structure maintain variables for r,g, and b .
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900