1

画像に特定の色が含まれているかどうかを判断する必要があります。

r:255
g:0
b:192

これを見つけましたが、画像に上記の色が含まれている場合は、ポイントを返す代わりにブール値を返す必要があります。

public static List<Point> FindAllPixelLocations(this Bitmap img, Color color)
        {
            var points = new List<Point>();

            int c = color.ToArgb();

            for (int x = 0; x < img.Width; x++)
            {
                for (int y = 0; y < img.Height; y++)
                {
                    if (c.Equals(img.GetPixel(x, y).ToArgb())) points.Add(new Point(x, y));
                }
            }

            return points;
        }
4

3 に答える 3

4

交換する必要があるようですね

if (c.Equals(img.GetPixel(x, y).ToArgb())) points.Add(new Point(x, y));

if (c.Equals(img.GetPixel(x, y).ToArgb())) return true;
于 2012-12-04T14:15:39.213 に答える
1

このようなもの:

    public static bool HasColor(this Bitmap img, Color color)
    {
        for (int x = 0; x < img.Width; x++)
        {
            for (int y = 0; y < img.Height; y++)
            {
                if (img.GetPixel(x, y) == color)
                    return true;
            }
        }
        return false;
    }
于 2012-12-04T14:19:11.420 に答える
0

正確には両方の答えが当てはまりますが GetPixel(x, y)SetPixel(x, y)色が非常に遅いことを知っておく必要があります。また、高解像度の画像の場合は適切ではありません。

LockBitmapこのために、ここでクラスを使用できます。ビットマップをより高速に処理する

これは約5倍高速です。

于 2012-12-04T14:36:08.940 に答える