I’m working on a task that includes image processing. I’ve found out, that I’m repeating one code over and over (DRY alert) and I’m just curious, whether there is a way to avoid it.
The code is :
for (int x = 0; x < image.Width; x++)
{
for (int y = 0; y < image.Height; y++)
{
byte pixelValue = Convert.ToByte(Byte.MaxValue * image.GetPixel(x, y).GetBrightness());
//Do something with pixelValue
}
}
The variety of tasks is wide, once I’m creating histogram, then I’m thresholding the image etc…. I feel there might be some solution using delegates, but I only have limited experience with them and clearly this is not the most important to think of.
Can you propose a solution in .NET Framework 2.0 as well?
Thanks
You could do it like this:
C# 2.0 Code