Beispiel #1
0
        private static void WriteAndCheckProfile(IMagickImageCollection images, PsdWriteDefines defines, int expectedLength)
        {
            using (MemoryStream memStream = new MemoryStream())
            {
                images.Write(memStream, defines);

                memStream.Position = 0;
                images.Read(memStream);
                CheckProfile(images[1], expectedLength);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Converts this instance to a <see cref="Bitmap"/> using the specified <see cref="ImageFormat"/>.
        /// Supported formats are: Gif, Icon, Tiff.
        /// </summary>
        /// <param name="self">The image collection.</param>
        /// <param name="imageFormat">The image format.</param>
        /// <typeparam name="TQuantumType">The quantum type.</typeparam>
        /// <returns>A <see cref="Bitmap"/> that has the specified <see cref="ImageFormat"/>.</returns>
        public static Bitmap ToBitmap <TQuantumType>(this IMagickImageCollection <TQuantumType> self, ImageFormat imageFormat)
            where TQuantumType : struct
        {
            Throw.IfNull(nameof(self), self);
            Throw.IfNull(nameof(imageFormat), imageFormat);

            var format = imageFormat.ToFormat();

            foreach (var image in self)
            {
                image.Settings.Format = format;
            }

            var memStream = new MemoryStream();

            self.Write(memStream);
            memStream.Position = 0;
            /* Do not dispose the memStream, the bitmap owns it. */
            return(new Bitmap(memStream));
        }