获取圆内的所有像素阵列

Yur*_*les 9 xna

我有这个:

在此输入图像描述

我需要知道圆圈内的所有像素.

谢谢.

Luc*_*ius 15

您正在寻找以下像素集:

圆方程

[R为你圆的半径和(M1,M2)的中心.

为了使这些像素迭代所有位置并将符合条件的那些存储在列表中:

List<int> indices = new List<int>();

for (int x = 0; x < width; x++)
{
    for (int y = 0; y < height; y++)
    {
        double dx = x - m1;
        double dy = y - m2;
        double distanceSquared = dx * dx + dy * dy;

        if (distanceSquared <= radiusSquared)
        {
            indices.Add(x + y * width);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 别客气。顺便说一句,您可以通过仅迭代圆的边界矩形中的像素来加快速度。 (4认同)