public void TestGetPixel() { var thisImage = new NetImage(); thisImage.ImageFormat = NetImage.ImageFormats.PNG; // No image data yet, value returned is zero var pixelColor = thisImage.GetPixel(640, 480); Assert.AreEqual(0, pixelColor); // Initialize image thisImage.BackgroundColor = NetImage.DotNETARGBToVBScriptRGB(0x32FF0000); thisImage.MaxX = 1024; thisImage.MaxY = 768; pixelColor = thisImage.GetPixel(640, 480); // Backgrounds can only be solid colors Assert.AreEqual(System.Drawing.Color.FromArgb(255, 255, 0, 0).ToArgb(), NetImage.VBScriptRGBToDotNETARGB(pixelColor)); // Verify color change thisImage.BackgroundColor = NetImage.DotNETARGBToVBScriptRGB(System.Drawing.Color.FromArgb(50, 0, 0, 255).ToArgb()); thisImage.ClearImage(); pixelColor = thisImage.GetPixel(640, 480); Assert.AreEqual(System.Drawing.Color.FromArgb(255, 0, 0, 255).ToArgb(), NetImage.VBScriptRGBToDotNETARGB(pixelColor)); }
public void TestClearImage() { const string outputFilePath = "../../Output/ClearImage.png"; var thisImage = new NetImage(); thisImage.LoadImage("../../Resources/1024x768-white.png"); thisImage.ImageFormat = NetImage.ImageFormats.PNG; thisImage.Filename = outputFilePath; thisImage.BackgroundColor = Color.FromArgb(0, 0, 0).ToArgb(); thisImage.ClearImage(); thisImage.AutoClear = false; thisImage.SaveImage(); var clearedImage = new NetImage(); clearedImage.LoadImage("../../Resources/1024x768-black.png"); var modifiedImage = new Bitmap(thisImage.RawNetImage); var comparisonImage = new Bitmap(clearedImage.RawNetImage); var thisConverter = new ImageConverter(); var modifiedImageBytes = new byte[0]; var comparisonImageBytes = new byte[0]; modifiedImageBytes = (byte[])thisConverter.ConvertTo(modifiedImage, modifiedImageBytes.GetType()); comparisonImageBytes = (byte[])thisConverter.ConvertTo(comparisonImage, comparisonImageBytes.GetType()); var hasher = new SHA256Managed(); byte[] modifiedImageHash = hasher.ComputeHash(modifiedImageBytes); byte[] comparisonImageHash = hasher.ComputeHash(comparisonImageBytes); bool isMatch = true; for (int i = 0; i < modifiedImageHash.Length && i < comparisonImageHash.Length && isMatch; i++) { if (modifiedImageHash[i] != comparisonImageHash[i]) { isMatch = false; } } Assert.IsTrue(isMatch); }
public void TestPropertyRawNetImage() { var thisImage = new NetImage(); thisImage.BackgroundColor = System.Drawing.Color.FromArgb(255, 0, 0, 0).ToArgb(); thisImage.MaxX = 1024; thisImage.MaxY = 768; thisImage.ClearImage(); if (thisImage.RawNetImage == null) { Assert.Fail(); } var imageSize = thisImage.RawNetImage.Size; var pixelColor = ((Bitmap)thisImage.RawNetImage).GetPixel(0, 0); Assert.AreEqual(1024, imageSize.Width); Assert.AreEqual(768, imageSize.Height); Assert.AreEqual(System.Drawing.Color.FromArgb(255, 0, 0, 0), pixelColor); }