public void Subtract(ref Sprite sp) { if (sp.Width != Width || sp.Height != Height) { return; } Bitmap sbmp = sp.GetBitmap(false); Bitmap dbmp = GetBitmap(false); int nPixels = Width * Height; int nSame = 0; int nNonTransp = 0; unchecked { for (int i = 0; i < nPixels; i++) { int x = i % Width; int y = i / Width; Color dclr = dbmp.GetPixel(x, y); Color sclr = sbmp.GetPixel(x, y); if (sclr.A != 0) { nNonTransp++; } Color clr = dclr; if (sclr == dclr) { clr = Color.FromArgb(0, 0, 0, 0); nSame++; } sbmp.SetPixel(x, y, clr); } } const int c_SubtractBias = 30; if (nSame > nNonTransp * c_SubtractBias / 100) { Difference = true; CreatePartition(sbmp); } }
public void Subtract( ref Sprite sp ) { if (sp.Width != Width || sp.Height != Height) { return; } Bitmap sbmp = sp.GetBitmap( false ); Bitmap dbmp = GetBitmap( false ); int nPixels = Width*Height; int nSame = 0; int nNonTransp = 0; unchecked { for (int i = 0; i < nPixels; i++) { int x = i%Width; int y = i/Width; Color dclr = dbmp.GetPixel( x, y ); Color sclr = sbmp.GetPixel( x, y ); if (sclr.A != 0) { nNonTransp++; } Color clr = dclr; if (sclr == dclr) { clr = Color.FromArgb( 0, 0, 0, 0 ); nSame++; } sbmp.SetPixel( x, y, clr ); } } const int c_SubtractBias = 30; if (nSame > nNonTransp*c_SubtractBias/100) { Difference = true; CreatePartition( sbmp ); } }