Ejemplo n.º 1
0
 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"]);
         }
     }
 }
Ejemplo n.º 2
0
        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));
                }
            }
        }
Ejemplo n.º 3
0
 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!");
     }
 }
Ejemplo n.º 4
0
        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);
                }
            }
        }
Ejemplo n.º 5
0
        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));
        }