public void ShouldIterateOverEveryPixel() { var image = new Bitmap(100, 100); var pixels = new List<Tuple<int,int>>(); image.ForEachPixel((x, y) => pixels.Add(Tuple.Create(x, y))); pixels.Distinct().Should().HaveCount(100 * 100); }
public void ShouldIterateOverEveryPixelThatIsNotIgnored() { var image = new Bitmap(100, 100); var pixels = new List<Tuple<int, int>>(); image.ForEachPixel( (x, y) => pixels.Add(Tuple.Create(x, y)), new[] { new IgnoreMask(0, 0, 9, 9) }); pixels.Distinct().Should().HaveCount((100 * 100) - (10 * 10)); }
private int GetCountOfPixelsThatMatch(Bitmap image) { var matchedPixels = 0; image.ForEachPixel( (x, y) => { var pixelColor = image.GetPixel(x, y).ToArgb(); if (pixelColor == this.colorToMatch) { matchedPixels++; } }); return matchedPixels; }
private static Color GetAverageColor(Bitmap image) { var colors = new List<Color>(); image.ForEachPixel( (x, y) => { var pixel = image.GetPixel(x, y); colors.Add(Color.FromArgb(pixel.ToArgb())); }); var averageColour = Color.FromArgb( (int)colors.Average(color => color.R), (int)colors.Average(color => color.G), (int)colors.Average(color => color.B)); return averageColour; }
public CompareResult AreEqual(Bitmap imageOne, Bitmap imageTwo) { if (imageOne.Width != imageTwo.Width) return new CompareResult { Equal = (false) }; if (imageOne.Height != imageTwo.Height) return new CompareResult { Equal = (false) }; var pixelsMatch = true; imageOne.ForEachPixel( (x, y) => { var pixelOne = imageOne.GetPixel(x, y); var pixelTwo = imageTwo.GetPixel(x, y); if (pixelOne != pixelTwo) { pixelsMatch = false; } }, ignoreMasks); return new CompareResult { Equal = (pixelsMatch) }; }