hey all,
im a dutch student and for a project I am responsible for the pc application. we are making a paint application, the picture that are drawed are saved in a bitmap so I can use the getpixel() function to get the collors form the image. the size of the pencil is 3 times as big as i should be, so i read out 1 out of 3 pixels, so the size of my image will be good for our lcd screen.
now I got a problem, in the loop were I use the getpixel() I keep getting the error: "Only assignment, call, increment, decrement, and new object expressions can be used as a statement"

        Color kleur;
        int x = 0;
        int y = 0;
        for (x <= 384; y < 155; )
        {
            kleur = b.GetPixel(x, y) ;
            y = y + 3;
            if (y > 155)
            {
                y = 0;
                x = x + 3;
            }

(I get the error over : x <= 384; )

Can anyone help me....?

kind regards,
Niels de Zaaijer

A better way (though not the only way) to write it would be with a nested for loop:

for (int x = 0;x<=384;x++)
{
    for (int y = 0;y<155;y++)
    {
//this way you wouldn't need the int x=0 and int y=0 at the top

because even if you were to use the two conditions in one loop you'd have to && them or || them together.

yeah, but thats not what i need, because now x and y will be set to 0 again every time they finsh the loop. and are you sure that the declaration of x and y at the top are the reason that i get this error?

Well, the reason you get the error is that what you have is not the proper syntax for a "for" loop. I was just suggesting declaring them in the body of the for loop but you are correct they won't persist if you do that.

I perhaps misunderstood what you needed, for that I apologize. However, I'm confused as to why you read in all of the y values with a constant x and only vary x once you've reached 155 on the y. Rather than the x++ and y++ in post #2 you could probably use x+=3 and y+=3 to skip the proper lines.

there is no is no need to apologize, I'm allready very happy about the fact you take the time to help me,
but the reason that i made my code the way it is is because the image that you draw in my program will be send to our microproccessor and that will send the data to our lcd screen on the product.

this lcd screen is 128 by 64 pixels.
and I could make my draw panel the same size ofcourse,
but then it looks like crap because that quite small on a pc screen because the pixels on your screen are much smaller then the pixels on the lcd screen. that's why we made the drawpanel 3 as big, and also the thickness of the pencil 3 pixels.

So that when I read out the pixels I just read out every first of 3, because then at the end I got exactly the right amount of pixels for my lcd screen.

does this help?.......

int x,y;
for (x = 0;x<=384;x+=3)
{
    for (y = 0;y<155;y+=3)
    {

will get you

{0,0},{0,3},{0,6} .....
{3,0},{3,3},{3,6} .....

So it will be compressed in both directions. You may need to adapt it to map properly onto your output device (so send {0,0} to pixel {0,0} and {3,0} to pixel {1,0}, etc.

int x=0,y;
while(x<=384)
{
for(y=0;y<=384;y+=3)
{
//write required code
x+=3;
}
}

I suggest you try out this code,this should work.
I did not clearly understand your error, but will ask you to check if there is any chance of stack overflow. If not, the above code should work.
Hope I helped. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.