日期:2014-05-17 浏览次数:20976 次
public Point GetFirstLocation(string strBigFile, string strSmallFile)
{
Bitmap bmpBig = new Bitmap(Image.FromFile(strBigFile));
Bitmap bmpSmall = new Bitmap(Image.FromFile(strSmallFile));
Color[,] clrSmall = new Color[bmpSmall.Width, bmpSmall.Height];
for (int i = 0; i < bmpSmall.Width; i++)
{
for (int j = 0; j < bmpSmall.Height; j++)
clrSmall[i, j] = bmpSmall.GetPixel(i, j);
}
bool bFlag = false; //是否找到标记
Point pt=new Point(-1,-1); //返回找到的起始点
for (int i = 0; i < bmpBig.Width - bmpSmall.Width; i++)
{
for (int j = 0; j < bmpBig.Height - bmpSmall.Height; j++)
{
if (bmpBig.GetPixel(i, j) == clrSmall[0, 0])
{
bFlag = true; //找到起始点
pt = new Point(i, j);
for (int x = i; x < i + bmpSmall.Width; x++)
{
for (int y = j; y < j + bmpSmall.Height; y++)
{
if (bmpBig.GetPixel(x, y) != clrSmall[x - i, y - j])
&nb