/// <summary> /// Read basic information about an image with multiple frames/pages. /// </summary> /// <param name="stream">The stream to read the image data from.</param> /// <returns>A <see cref="MagickImageInfo"/> iteration.</returns> /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception> public static IEnumerable <MagickImageInfo> ReadCollection(Stream stream) { using (IMagickImageCollection images = new MagickImageCollection()) { images.Ping(stream); foreach (MagickImage image in images) { MagickImageInfo info = new MagickImageInfo(); info.Initialize(image); yield return(info); } } }
/// <summary> /// Read basic information about an image with multiple frames/pages. /// </summary> /// <param name="fileName">The fully qualified name of the image file, or the relative image file name.</param> /// <param name="readSettings">The settings to use when reading the image.</param> /// <returns>A <see cref="MagickImageInfo"/> iteration.</returns> /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception> public static IEnumerable <IMagickImageInfo> ReadCollection(string fileName, MagickReadSettings readSettings) { using (IMagickImageCollection images = new MagickImageCollection()) { images.Ping(fileName, readSettings); foreach (MagickImage image in images) { MagickImageInfo info = new MagickImageInfo(); info.Initialize(image); yield return(info); } } }
/// <summary> /// Read basic information about an image with multiple frames/pages. /// </summary> /// <param name="data">The byte array to read the information from.</param> /// <param name="offset">The offset at which to begin reading data.</param> /// <param name="count">The maximum number of bytes to read.</param> /// <returns>A <see cref="IMagickImageInfo"/> iteration.</returns> /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception> public static IEnumerable <IMagickImageInfo> ReadCollection(byte[] data, int offset, int count) { using (var images = new MagickImageCollection()) { images.Ping(data, offset, count); foreach (var image in images) { var info = new MagickImageInfo(); info.Initialize(image); yield return(info); } } }
/// <summary> /// Read basic information about an image with multiple frames/pages. /// </summary> /// <param name="fileName">The fully qualified name of the image file, or the relative image file name.</param> /// <returns>A <see cref="IMagickImageInfo"/> iteration.</returns> /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception> public static IEnumerable <IMagickImageInfo> ReadCollection(string fileName) { using (var images = new MagickImageCollection()) { images.Ping(fileName); foreach (var image in images) { var info = new MagickImageInfo(); info.Initialize(image); yield return(info); } } }
/// <summary> /// Read basic information about an image with multiple frames/pages. /// </summary> /// <param name="data">The byte array to read the information from.</param> /// <param name="readSettings">The settings to use when reading the image.</param> /// <returns>A <see cref="MagickImageInfo"/> iteration.</returns> /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception> public static IEnumerable <MagickImageInfo> ReadCollection(byte[] data, MagickReadSettings readSettings) { using (MagickImageCollection images = new MagickImageCollection()) { images.Ping(data, readSettings); foreach (MagickImage image in images) { MagickImageInfo info = new MagickImageInfo(); info.Initialize(image); yield return(info); } } }
/// <summary> /// Read basic information about an image with multiple frames/pages. /// </summary> /// <param name="data">The span of bytes to read the information from.</param> /// <returns>A <see cref="IMagickImageInfo"/> iteration.</returns> /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception> public static IReadOnlyCollection <IMagickImageInfo> ReadCollection(ReadOnlySpan <byte> data) { var result = new List <MagickImageInfo>(); using (var images = new MagickImageCollection()) { images.Ping(data); foreach (var image in images) { var info = new MagickImageInfo(); info.Initialize(image); result.Add(info); } } return(result); }
public void Test_ReadSettings() { MagickReadSettings settings = new MagickReadSettings(); settings.FontFamily = "Courier New"; settings.FillColor = MagickColors.Gold; settings.FontPointsize = 80; settings.Format = MagickFormat.Text; settings.TextGravity = Gravity.Center; using (MagickImageCollection images = new MagickImageCollection(Files.ImageMagickTXT, settings)) { Assert.AreEqual(2, images.Count); ColorAssert.AreEqual(MagickColors.Gold, images[0], 348, 648); } using (MagickImageCollection images = new MagickImageCollection()) { images.Ping(Files.ImageMagickTXT, settings); Assert.AreEqual(2, images.Count); ExceptionAssert.Throws<InvalidOperationException>(() => { ColorAssert.AreEqual(MagickColors.Gold, images[0], 348, 648); }); } }
public void Test_Ping() { MagickImageCollection 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(); }