public void Test_Ping()
        {
            IMagickImageCollection collection = new MagickImageCollection();

            ExceptionAssert.Throws <ArgumentException>(delegate()
            {
                collection.Ping(new byte[0]);
            });

            ExceptionAssert.Throws <ArgumentNullException>(delegate()
            {
                collection.Ping((byte[])null);
            });

            ExceptionAssert.Throws <ArgumentNullException>(delegate()
            {
                collection.Ping((Stream)null);
            });

            ExceptionAssert.Throws <ArgumentNullException>(delegate()
            {
                collection.Ping((string)null);
            });

            ExceptionAssert.Throws <ArgumentException>(delegate()
            {
                collection.Ping(Files.Missing);
            });

            collection.Ping(Files.FujiFilmFinePixS1ProJPG);
            Test_Ping(collection);
            Assert.AreEqual(600, collection[0].Width);
            Assert.AreEqual(400, collection[0].Height);

            collection.Ping(new FileInfo(Files.FujiFilmFinePixS1ProJPG));
            Test_Ping(collection);
            Assert.AreEqual(600, collection[0].Width);
            Assert.AreEqual(400, collection[0].Height);

            collection.Ping(File.ReadAllBytes(Files.FujiFilmFinePixS1ProJPG));
            Test_Ping(collection);
            Assert.AreEqual(600, collection[0].Width);
            Assert.AreEqual(400, collection[0].Height);

            collection.Read(Files.SnakewarePNG);
            Assert.AreEqual(286, collection[0].Width);
            Assert.AreEqual(67, collection[0].Height);
            using (PixelCollection pixels = collection[0].GetPixels())
            {
                Assert.AreEqual(38324, pixels.ToArray().Length);
            }

            collection.Dispose();
        }
Пример #2
0
        private static void WritePixels(MagickImage image, string fileName)
        {
            using (PixelCollection pixels = image.GetPixels())
            {
                ushort[] data  = pixels.ToArray();
                byte[]   bytes = new byte[data.Length * 2];

                Buffer.BlockCopy(data, 0, bytes, 0, bytes.Length);
                File.WriteAllBytes(fileName, bytes);
            }
        }