I'm trying to make a C# function that returns the R, G and B values of every fourth pixel from a screenshot bitmap. This is part of my code.
for (int ix = 4; ix < 1366; ix = ix + 4)
{
x = x + 4;
for (int iy = 3; iy < 768; iy = iy + 4)
{
y = y + 4;
System.Drawing.Color pixelcolor = screenshot.GetPixel(x,y);
red = kolorpiksela.R;
green = kolorpiksela.G;
blue = kolorpiksela.B;
sumR = sumR + red;
sumG = sumG + green;
sumB = sumB + blue;
}
}
Where screenshot
is a bitmap. At the end the "sums" values are divided by the number of pixels. My problem is that it doesn't work. The error I get is:
An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in System.Drawing.dll
Additional information: Parameter must be positive and < Height.
I think the reason for the error is that pixelcolor
should be reset every step, but I tried to do that for the last 2 days. No success.