Beispiel #1
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));
                }
            }
        }
Beispiel #2
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);
                }
            }
        }
Beispiel #3
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));
        }