Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone
I have written such code like this

C++
UINT width = bmp->GetWidth();
UINT height = bmp->GetHeight();

cout << "The Width is   " << width;
for(i=0;i<width;i++)>
{
	//cout << "Tes";
	for(j=0;j<height;j++)>
	{

	   bmp->GetPixel(i,j,&color);
	   if(color = 255,255,255)
	   {
				
		mxCoordinateX[l]= i;l++;
	        mxCoordinateY[m]= j;m++;
				
	   }
        }
}


but there was an error in run time regarding argb
C++
Status status = SetStatus(DllExports::GdipBitmapGetPixel(
static_cast<gpbitmap>(nativeImage),
x, y,        
&argb));


my program wants get coordinate of rectangle (unfilled, just line) in a white-background bitmap by check if the pixel is black then save the coordinates but error appeared i showed it above..
Could you give me advice?
Thanks
Posted
Updated 25-Sep-11 14:22pm
v2

1 solution

The line
C++
if(color = 255,255,255)
probably does do what you think it does.

First, in C++, operator = is assignment operator and not equality operator.

Second, in C++, a comma allows multiple expressions when normally one expression is expected and the result is taken from the rightmost one.

Thus, that statement would essentially be equivalent to:

C++
255;
255;
color = 255;
if (color) { ... }

For more information, take a look at:
http://www.cplusplus.com/doc/tutorial/operators/[^]

And also:
http://msdn.microsoft.com/en-us/library/zs06xbxh(v=VS.100).aspx[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 25-Sep-11 22:29pm    
Good catch of very basic C++ stuff, my 5.
--SA
Kay Andrian Fikar 26-Sep-11 0:18am    
yes, when i type

if(color == 255,255,255)

it showed error Error :
error C2678: binary '==' : no operator found which takes a left-hand operand of type 'Gdiplus::Color' (or there is no acceptable conversion) c:\users\user\documents\visual studio 2008\projects\dasar imageprocessing\dasar imageprocessing\dasar imageprocessing.cpp

so color type cannot be used for conditional statements?
but i want to check if a black color exist in this pixel for example then i save the coordinate
Chuck O'Toole 26-Sep-11 2:41am    
The message below is for you, I put the reply in the wrong place. Sorry.
Chuck O'Toole 26-Sep-11 3:21am    
PS, 255,255,255 is not black, it's white (all colors full on). Black is 0,0,0
Chuck O'Toole 26-Sep-11 2:40am    
No silly, it's not that you can't use a color type, it's that "255,255,255" are just 3 numbers. Oh, you wanted them to be treated as a "RGB()" value? Just how is the compiler to know that? Instead, create a 24 bit COLORREF value with "RGB(255,255,255)"

(oops, I replied to the wrong message, sorry)

Note, in your code shown, you do not define "color" but you obviously have it somewhere, care to share the definition with us?

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