public void TestPropertyProgressiveJPEGEncoding()
        {
            var thisImage = new NetImage();
            var initValue = thisImage.ProgressiveJPEGEncoding;

            thisImage.ProgressiveJPEGEncoding = !thisImage.ProgressiveJPEGEncoding;
            var modifiedValue = thisImage.ProgressiveJPEGEncoding;

            Assert.AreNotEqual(initValue, modifiedValue);
        }
        public void TestPropertyAutoClear()
        {
            var thisImage = new NetImage();
            var initValue = thisImage.AutoClear;

            thisImage.AutoClear = !thisImage.AutoClear;
            var modifiedValue = thisImage.AutoClear;

            Assert.AreNotEqual(initValue, modifiedValue);
        }
        public void TestPropertyTextAngle()
        {
            var thisImage = new NetImage();

            thisImage.TextAngle = 0;
            Assert.AreEqual(0f, thisImage.TextAngle);

            thisImage.TextAngle = 360;
            Assert.AreEqual(360f, thisImage.TextAngle);

            thisImage.TextAngle = 500;
            Assert.AreEqual(360f, thisImage.TextAngle);
        }
        public void TestPropertyMaxY()
        {
            var thisImage = new NetImage();

            Assert.AreEqual(0, thisImage.MaxY);

            thisImage.MaxY = 768;
            // maxX value not set, so image is still null
            Assert.AreEqual(0, thisImage.MaxY);

            thisImage.MaxX = 1024;
            Assert.AreEqual(768, thisImage.MaxY);
        }
        public void TestGetImageSize()
        {
            var thisImage = new NetImage();

            thisImage.LoadImage("../../Resources/1024x768.png");

            int width, height;

            thisImage.GetImageSize(out width, out height);

            Assert.AreEqual(1024, width);
            Assert.AreEqual(768, height);
        }
        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 TestPropertyPenWidth()
        {
            var thisImage = new NetImage();

            thisImage.PenWidth = 0;
            Assert.AreEqual(1, thisImage.PenWidth);

            thisImage.PenWidth = 10;
            Assert.AreEqual(10, thisImage.PenWidth);

            thisImage.PenWidth = -50;
            Assert.AreEqual(1, thisImage.PenWidth);

            thisImage.PenWidth = 200;
            Assert.AreEqual(200, thisImage.PenWidth);
        }
        public void TestPropertyJPGQuality()
        {
            var thisImage = new NetImage();

            thisImage.JPEGQuality = 100;
            Assert.AreEqual(100, thisImage.JPEGQuality);

            thisImage.JPEGQuality = 200;
            Assert.AreEqual(100, thisImage.JPEGQuality);

            thisImage.JPEGQuality = 0;
            Assert.AreEqual(0, thisImage.JPEGQuality);

            thisImage.JPEGQuality = -52;
            Assert.AreEqual(0, thisImage.JPEGQuality);
        }
        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);
        }
Beispiel #10
0
        public void TestPropertyY()
        {
            var thisImage = new NetImage();

            Assert.AreEqual(0, thisImage.Y);

            thisImage.Y = 50;
            Assert.AreEqual(0, thisImage.Y); // Should be zero still because image dimensions haven't been defined

            thisImage.MaxX = 1024;
            thisImage.MaxY = 768;

            thisImage.Y = 50;
            Assert.AreEqual(50, thisImage.Y);

            thisImage.Y = -10;
            Assert.AreEqual(0, thisImage.Y);
        }
Beispiel #11
0
        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);
        }
Beispiel #12
0
        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);
        }
Beispiel #13
0
        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);
        }
Beispiel #14
0
        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);
        }
Beispiel #15
0
        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);
        }
Beispiel #16
0
        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);
        }
Beispiel #17
0
        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);
        }
Beispiel #18
0
        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)));
            }
        }
Beispiel #19
0
        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);
        }
Beispiel #20
0
        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);
            }
        }
Beispiel #21
0
        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);
        }
Beispiel #22
0
        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();
            }
        }
Beispiel #23
0
        public void TestPropertyExpires()
        {
            var thisImage = new NetImage();

            Assert.That(Convert.ToDateTime(thisImage.Expires) > DateTime.Now);
        }