public void Image_Dimensions() { foreach (var file in GetTestImageFiles()) { using (var bmp = new Bitmap(file)) { var dims = Image.Dimensions(bmp); Assert.AreEqual(bmp.Width, dims["width"]); Assert.AreEqual(bmp.Height, dims["height"]); } } }
public void Image_Write() { var tmp = GetNewFileNameOnTempPath("png"); using (var bmp = new Bitmap(Path.Combine(TestDirectory, @"core\files\images\testImage.png"))) { Image.WriteToFile(tmp, bmp); using (var newBmp = new Bitmap(tmp)) { Assert.AreEqual(Image.Pixels(bmp), Image.Pixels(newBmp)); } } }
public void Image_ReadFromFile() { foreach (var file in GetTestImageFiles()) { Image.ReadFromFile(File.FromPath(file)); Assert.DoesNotThrow( () => { using (System.IO.File.OpenRead(file)) { } //Check that it's not locked }, "File is locked after being read!"); } }
public void Image_Pixels() { foreach (var file in GetTestImageFiles()) { using (var bmp = new Bitmap(file)) { var allPixels = Image.Pixels(bmp); Assert.AreEqual(bmp.Height, allPixels.Length); Assert.AreEqual(bmp.Width, allPixels[0].Length); const int samples = 40; var samplePixels = Image.Pixels(bmp, xSamples: samples, ySamples: samples); Assert.AreEqual(samples, samplePixels.Length); Assert.AreEqual(samples, samplePixels[0].Length); } } }
public void Image_FromPixels() { const int size = 50; var rectPixels = Enumerable.Repeat(Enumerable.Repeat(Color.ByColor(System.Drawing.Color.Blue), size).ToArray(), size) .ToArray(); var bmpFromRect = Image.FromPixels(rectPixels); Assert.AreEqual(size, bmpFromRect.Width); Assert.AreEqual(size, bmpFromRect.Height); var flatPixels = rectPixels.SelectMany(x => x).ToArray(); var bmpFromFlat = Image.FromPixels(flatPixels, size, size); Assert.AreEqual(size, bmpFromFlat.Width); Assert.AreEqual(size, bmpFromFlat.Height); Assert.AreEqual(Image.Pixels(bmpFromRect), Image.Pixels(bmpFromFlat)); }