Made it hotnoob watching videos and researching the method that uses "LockBits".
Here is the code:
PHP Code:
private struct PixelData
{
public byte red;
public byte green;
public byte blue;
public byte alpha;
}
/// <summary>
/// Se utiliza para obtener las coordenadas de una imagen dentro de otra. Devuelve el resultado en formato "Point"
/// </summary>
/// <param name="Fondo">Imagen base donde se encuentra la que se va a buscar</param>
/// <param name="Imagen">Imagen que se desea buscar</param>
/// <param name="Var">Cantidad permitida de variacion de pixeles, mientras menor sea menos sensible será el algoritmo</param>
/// <returns>Point</returns>
public unsafe Point Busqueda(Bitmap Fondo, Bitmap Imagen, int Var)
{
bool Encontrado = false;
int Xinterno = 0;
int Yinterno = 0;
BitmapData FondoLock = Fondo.LockBits(new Rectangle(0, 0, Fondo.Width, Fondo.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppRgb);
BitmapData ImagenLock = Imagen.LockBits(new Rectangle(0, 0, Imagen.Width, Imagen.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppRgb);
PixelData* FondoP = (PixelData*)FondoLock.Scan0.ToPointer();
PixelData* ImagenP = (PixelData*)ImagenLock.Scan0.ToPointer();
for (int Y = 0; Y < (FondoLock.Height - ImagenLock.Height); Y++)
{
for (int X = 0; X < (FondoLock.Width - ImagenLock.Width); X++)
{
PixelData* RFondo = (PixelData*)(FondoP + Y * Fondo.Width + X);
PixelData* RImagen = (PixelData*)(ImagenP);
if ((Math.Abs(RFondo->red - RImagen->red) <= Var) && (Math.Abs(RFondo->blue - RImagen->blue) <= Var) && (Math.Abs(RFondo->green - RImagen->green) <= Var))
{
Encontrado = true;
for (Yinterno = 0; Yinterno < (ImagenLock.Height); Yinterno++)
{
for (Xinterno = 0; Xinterno < (ImagenLock.Width); Xinterno++)
{
PixelData* MFondo = (PixelData*)(RFondo + Yinterno * FondoLock.Width + Xinterno);
PixelData* MImagen = (PixelData*)(RImagen + Yinterno * ImagenLock.Width + Xinterno);
if ((Math.Abs(MFondo->red - MImagen->red) > Var) || (Math.Abs(MFondo->blue - MImagen->blue) > Var) || (Math.Abs(MFondo->green - MImagen->green) > Var))
{
Encontrado = false;
}
}
}
if (Encontrado == true)
{
Fondo.UnlockBits(FondoLock);
Imagen.UnlockBits(ImagenLock);
return new Point((X + (Xinterno / 2)), (Y + (Yinterno / 2)));
}
}
}
}
Fondo.UnlockBits(FondoLock);
Imagen.UnlockBits(ImagenLock);
return new Point();
}







