获取圆圈内的所有像素阵列 [英] Get all pixel array inside circle

查看:23
本文介绍了获取圆圈内的所有像素阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个:

我需要知道圆内数组中的所有像素.

And I need to know all pixels in array inside the circle.

谢谢.

推荐答案

您正在寻找以下像素集:

You are looking for the following set of pixels:

r 是圆的半径,(m1, m2) 是圆心.

with r being the radius of your circle and (m1, m2) the center.

为了让这些像素遍历所有位置并将满足条件的像素存储在列表中:

In order to get these pixels iterate over all positions and store those which meet the criteria in a list:

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

这篇关于获取圆圈内的所有像素阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆