Populating a color array with every 8th pixel in an image. C#

Posted by Piper on Stack Overflow See other posts from Stack Overflow or by Piper
Published on 2011-01-01T00:30:28Z Indexed on 2011/01/01 0:54 UTC
Read the original article Hit count: 178

Filed under:
|
|

I have an image that is 512x280 pixels. I want to populate a 64x35 array with every 8th pixel in the matrix.

Here is what I have right now:

        Color[,] imgArray = new Color[b.Width, b.Height];
        for (int y = 0; y < 35; y++)
        {
            for (int x = 0; x < 64; x++)
            {
                imgArray[x, y] = b.GetPixel(x, y);
            }
        }

But that will get just the top corner of the image. How would I change the loop so it grabs every 8th pixel to fill the array with?

edit: I think I may have gotten it. Can someone read this and assure me that it is correct?

        Color[,] imgArray = new Color[64, 35];
        for (int y = 0; y < 280; y+=8)
        {
            for (int x = 0; x < 512; x+=8)
            {
                imgArray[x, y] = b.GetPixel(x, y);
            }
        }

© Stack Overflow or respective owner

Related posts about c#

Related posts about multidimensional-array