public void TestDarkenImage() { const string outputFilePath = "../../Output/Brightness-Darken_image.jpg"; var thisImage = new NetImage(); thisImage.LoadImage("../../Resources/1024x768-white.png"); thisImage.Filename = outputFilePath; thisImage.DarkenImage(50); thisImage.SaveImage(); // TODO : Check RGB values Assert.Pass("DarkenImage passed but does not verify RGB Values"); }
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 TestRotate180Degrees() { const string outputFilePath = "../../Output/Rotate-180_degrees.jpg"; var thisImage = new NetImage(); thisImage.LoadImage("../../Resources/1024x768.png"); thisImage.Filename = outputFilePath; thisImage.RotateImage(180); thisImage.SaveImage(); int width, height; thisImage.GetImageFileSize(outputFilePath, out width, out height); Assert.AreEqual(1024, width); Assert.AreEqual(768, height); }
public void TestFlipVertical() { const string outputFilePath = "../../Output/Flip-Vertical.jpg"; var thisImage = new NetImage(); thisImage.LoadImage("../../Resources/1024x768.png"); thisImage.Filename = outputFilePath; thisImage.FlipImage(NetImage.FlipDirections.Vertical); thisImage.SaveImage(); int width, height; thisImage.GetImageFileSize(outputFilePath, out width, out height); Assert.AreEqual(1024, width); Assert.AreEqual(768, height); }
public void TestCropImage() { const string outputFilePath = "../../Output/CropImage.jpg"; var thisImage = new NetImage(); thisImage.LoadImage("../../Resources/1024x768.png"); thisImage.Filename = outputFilePath; thisImage.CropImage(10, 50, 800, 600); thisImage.SaveImage(); int width, height; thisImage.GetImageFileSize(outputFilePath, out width, out height); Assert.AreEqual(800, width); Assert.AreEqual(600, height); }
public void TestResizePortraitWithoutConstraint() { const string outputFilePath = "../../Output/Resize-Variant_aspect_ratio_portrait-Unconstrained.jpg"; var thisImage = new NetImage(); thisImage.LoadImage("../../Resources/900x1440.png"); thisImage.Filename = outputFilePath; thisImage.ConstrainResize = false; thisImage.Resize(800, 600); thisImage.SaveImage(); int width, height; thisImage.GetImageFileSize(outputFilePath, out width, out height); Assert.AreEqual(800, width); Assert.AreEqual(600, height); }
public void TestResizeLandscapeWithConstraint() { const string outputFilePath = "../../Output/Resize-Variant_aspect_ratio_landscape-Constrained.jpg"; var thisImage = new NetImage(); thisImage.LoadImage("../../Resources/1440x900.png"); thisImage.Filename = outputFilePath; thisImage.ConstrainResize = true; thisImage.Resize(800, 600); thisImage.SaveImage(); int width, height; thisImage.GetImageFileSize(outputFilePath, out width, out height); Assert.AreEqual(800, width); Assert.AreEqual(600, height); }
public void TestResizeSameAspectRatioWithConstraint() { const string outputFilePath = "../../Output/Resize-Same_aspect_ratio-Constrained.jpg"; var thisImage = new NetImage(); thisImage.LoadImage("../../Resources/1024x768.png"); thisImage.Filename = outputFilePath; thisImage.ConstrainResize = true; thisImage.Resize(800, 600); thisImage.SaveImage(); int width, height; thisImage.GetImageFileSize(outputFilePath, out width, out height); Assert.AreEqual(800, width); Assert.AreEqual(600, height); }
public void TestLineTo() { const string outputFilePath = "../../Output/LineTo.png"; var redColor = System.Drawing.Color.FromArgb(255, 255, 0, 0).ToArgb(); var blueColor = System.Drawing.Color.FromArgb(255, 0, 0, 255).ToArgb(); var thisImage = new NetImage(); thisImage.BackgroundColor = NetImage.DotNETARGBToVBScriptRGB(System.Drawing.Color.FromArgb(255, 255, 255, 255).ToArgb()); thisImage.MaxX = 1024; thisImage.MaxY = 1024; thisImage.Filename = outputFilePath; thisImage.ImageFormat = NetImage.ImageFormats.PNG; // bitmap form to preserve pixels thisImage.AutoClear = false; thisImage.X = 0; thisImage.Y = 0; thisImage.PenColor = NetImage.DotNETARGBToVBScriptRGB(redColor); thisImage.PenWidth = 1; thisImage.LineTo(1023, 1023); thisImage.PenColor = NetImage.DotNETARGBToVBScriptRGB(blueColor); thisImage.LineTo(1023, 0); thisImage.SaveImage(); // Verify diagonal pixels for (int x = 0; x <= 1022; x++) // Only to 1022 because blue line covers up bottom right pixel { Assert.AreEqual(redColor, NetImage.VBScriptRGBToDotNETARGB(thisImage.GetPixel(x, x))); } // Verify vertical pixels for (int y = 0; y <= 1023; y++) { Assert.AreEqual(blueColor, NetImage.VBScriptRGBToDotNETARGB(thisImage.GetPixel(1023, y))); } }
public void TestRotate90DegreesWithCrop() { const string outputFilePath = "../../Output/Rotate-90_degrees_with_crop.jpg"; int originalWidth = 0; int originalHeight = 0; var thisImage = new NetImage(); thisImage.LoadImage("../../Resources/1024x768.png"); thisImage.GetImageSize(out originalWidth, out originalHeight); thisImage.Filename = outputFilePath; thisImage.RotateImage(90); thisImage.ConstrainResize = true; thisImage.Resize(originalWidth, originalHeight); thisImage.SaveImage(); int width, height; thisImage.GetImageFileSize(outputFilePath, out width, out height); Assert.AreEqual(originalWidth, width); Assert.AreEqual(originalHeight, height); }
public void TestGIMPImage() { const string outputFilePath = "../../Output/gimpimage.jpg"; var thisImage = new NetImage(); thisImage.LoadImage("../../Resources/gimpimage.jpg"); if (thisImage.Error.Length <= 0) { int width = 0; int height = 0; thisImage.GetImageSize(out width, out height); if (width > 0 && height > 0) { thisImage.Filename = outputFilePath; thisImage.SaveImage(); if (thisImage.Error.Length <= 0) { var fileInfo = new System.IO.FileInfo(outputFilePath); Assert.That(fileInfo.Length > 0, "Image filesize is zero bytes"); } else { Assert.Fail("SaveImage() error: " + thisImage.Error); } } else { Assert.Fail("Loaded image sizes incorrect - width: " + width.ToString(CultureInfo.InvariantCulture) + ", height: " + height.ToString(CultureInfo.InvariantCulture)); } } else { Assert.Fail("LoadImage() error: " + thisImage.Error); } }
public void TestFillRect() { const string outputFilePath = "../../Output/FillRect.png"; var thisImage = new NetImage(); thisImage.LoadImage("../../Resources/1024x768-white.png"); thisImage.ImageFormat = NetImage.ImageFormats.PNG; thisImage.Filename = outputFilePath; thisImage.BackgroundColor = NetImage.DotNETARGBToVBScriptRGB(Color.Red.ToArgb()); thisImage.FillRect(10, 10, 20, 20); thisImage.AutoClear = false; // Don't clear on save so we can still access raw image thisImage.SaveImage(); var color1 = ((Bitmap)thisImage.RawNetImage).GetPixel(9, 9).ToArgb(); var color2 = ((Bitmap)thisImage.RawNetImage).GetPixel(10, 10).ToArgb(); var color3 = ((Bitmap)thisImage.RawNetImage).GetPixel(20, 20).ToArgb(); var color4 = ((Bitmap)thisImage.RawNetImage).GetPixel(21, 21).ToArgb(); Assert.AreEqual(Color.White.ToArgb(), color1); Assert.AreEqual(Color.Red.ToArgb(), color2); Assert.AreEqual(Color.Red.ToArgb(), color3); Assert.AreEqual(Color.White.ToArgb(), color4); }
public void TestAutoClear() { const string outputFilePath = "../../Output/AutoClear.jpg"; var thisImage = new NetImage(); thisImage.LoadImage("../../Resources/1024x768.png"); thisImage.AutoClear = true; thisImage.Filename = outputFilePath; thisImage.SaveImage(); try { // On SaveImage() call, the image data should be null and // generate an exception. If it doesn't, we know the // data was not cleared. thisImage.RotateImage(90); Assert.Fail("Image data not cleared"); } catch (Exception) { Assert.Pass(); } }