用c#语言,读出一张图片中的红点的位置

来源:百度知道 编辑:UC知道 时间:2024/05/30 03:00:12
请高手来帮一下!假如有一张图片,图片中有一个红点,我想知道怎么计算出图片中的红点在图片中的坐标。各位大虾帮帮忙,最好能给我代码
能不能有更快的方法啊?

仅供参考

Bitmap bmp = new Bitmap(Image.FromFile("test.png"));
BitmapData bmdat = bmp.LockBits(new Rectangle(Point.Empty, bmp.Size), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
Point pt = new Point(-1, -1);

unsafe
{
byte* pix = (byte*)bmdat.Scan0;

for (int y = 0; y < bmdat.Height; y++)
for (int x = 0; x < bmdat.Stride; x += 3)
if (pix[y * bmdat.Stride + x + 0] == 0 && pix[y * bmdat.Stride + x + 1] == 0 && pix[y * bmdat.Stride + x + 2] == 255)
{
pt = new Point(x / 3, y); // 红点
break;
}
}

bmp.UnlockBits(bmdat);

if (pt.X > -1 && pt.Y > -1)
MessageBox.Show(string.Format(&q