用图像中的每 8 个像素填充一个颜色数组。 C#

发布于 2024-10-10 01:57:54 字数 695 浏览 0 评论 0原文

我有一个 512x280 像素的图像。我想用矩阵中的每 8 个像素填充一个 64x35 数组。

这就是我现在所拥有的:

        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);
            }
        }

但这只会到达图像的顶角。我将如何更改循环,以便它抓取每 8 个像素来填充数组?

编辑:我想我可能已经明白了。有人可以读一下这篇文章并向我保证它是正确的吗?

        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);
            }
        }

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);
            }
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

删除会话 2024-10-17 01:57:54

获得像素后,只需将坐标乘以 8:

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

Simply multiply the coordinates by 8 when you get the pixels:

Color[,] imgArray = new Color[64, 35];
for (int y = 0; y < 35; y++) {
  for (int x = 0; x < 64; x++) {
    imgArray[x, y] = b.GetPixel(x * 8, y * 8);
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文