コード例 #1
0
ファイル: GifOptimizer.cs プロジェクト: dlemstra/Magick.NET
 private static void DoLosslessCompress(FileInfo file)
 {
   using (MagickImageCollection images = new MagickImageCollection(file))
   {
     if (images.Count == 1)
     {
       DoLosslessCompress(file, images[0]);
       return;
     }
   }
 }
コード例 #2
0
		public void Test_Collection_Exceptions()
		{
			using (MagickImageCollection collection = new MagickImageCollection())
			{
				MagickReadSettings settings = new MagickReadSettings();
				settings.PixelStorage = new PixelStorageSettings();

				ExceptionAssert.Throws<ArgumentException>(delegate()
				{
					collection.Read(Files.RoseSparkleGIF, settings);
				});
			}
		}
コード例 #3
0
		public void Test_Collection_Read()
		{
			using (MagickImageCollection collection = new MagickImageCollection())
			{
				MagickReadSettings settings = new MagickReadSettings();
				settings.Density = new MagickGeometry(150, 150);

				collection.Read(Files.RoseSparkleGIF, settings);

				Assert.AreEqual(150, collection[0].Density.Width);

				settings = null;
				collection.Read(Files.RoseSparkleGIF, settings);
			}
		}
コード例 #4
0
		public void Test_AddRange()
		{
			using (MagickImageCollection collection = new MagickImageCollection(Files.RoseSparkleGIF))
			{
				Assert.AreEqual(3, collection.Count);

				collection.AddRange(Files.RoseSparkleGIF);
				Assert.AreEqual(6, collection.Count);

				collection.AddRange(collection);
				Assert.AreEqual(12, collection.Count);

				List<MagickImage> images = new List<MagickImage>();
				images.Add(new MagickImage("xc:red", 100, 100));
				collection.AddRange(images);
				Assert.AreEqual(13, collection.Count);
			}
		}
コード例 #5
0
ファイル: ThePsdCoder.cs プロジェクト: lonelyxmas/Magick.NET
        public void ShouldReadTheProfileForAllLayers()
        {
            var readSettings = new MagickReadSettings
            {
                Defines = new PsdReadDefines
                {
                    ReplicateProfile = true,
                },
            };

            using (var images = new MagickImageCollection(Files.Coders.LayerStylesSamplePSD, readSettings))
            {
                Assert.Equal(4, images.Count);

                foreach (var image in images)
                {
                    Assert.NotNull(image.Get8BimProfile());
                }
            }
        }
コード例 #6
0
                public void ShouldUseTheSpecifiedFormat()
                {
                    using (var input = new MagickImageCollection(Files.CirclePNG))
                    {
                        using (var memoryStream = new MemoryStream())
                        {
                            using (var stream = new NonSeekableStream(memoryStream))
                            {
                                input.Write(stream, MagickFormat.Tiff);

                                memoryStream.Position = 0;
                                using (var output = new MagickImageCollection(stream))
                                {
                                    Assert.Single(output);
                                    Assert.Equal(MagickFormat.Tiff, output[0].Format);
                                }
                            }
                        }
                    }
                }
コード例 #7
0
ファイル: CombiningImages.cs プロジェクト: zBrianW/Magick.NET
        public static void MergeMultipleImages()
        {
            using (MagickImageCollection images = new MagickImageCollection())
            {
                // Add the first image
                MagickImage first = new MagickImage(SampleFiles.SnakewarePng);
                images.Add(first);

                // Add the second image
                MagickImage second = new MagickImage(SampleFiles.SnakewarePng);
                images.Add(second);

                // Create a mosaic from both images
                using (IMagickImage result = images.Mosaic())
                {
                    // Save the result
                    result.Write(SampleFiles.OutputDirectory + "Mosaic.png");
                }
            }
        }
コード例 #8
0
ファイル: ResizeImage.cs プロジェクト: weinre/OCR-Invoice
        public static void ResizeAnimatedGif()
        {
            // Read from file
            using (MagickImageCollection collection = new MagickImageCollection(SampleFiles.SnakewareGif))
            {
                // This will remove the optimization and change the image to how it looks at that point
                // during the animation. More info here: http://www.imagemagick.org/Usage/anim_basics/#coalesce
                collection.Coalesce();

                // Resize each image in the collection to a width of 200. When zero is specified for the height
                // the height will be calculated with the aspect ratio.
                foreach (MagickImage image in collection)
                {
                    image.Resize(200, 0);
                }

                // Save the result
                collection.Write(SampleFiles.OutputDirectory + "Snakeware.resized.gif");
            }
        }
コード例 #9
0
ファイル: TheWriteMethod.cs プロジェクト: Tommy-Hu/Magick.NET
                public void ShouldUseTheFileExtension()
                {
                    var readSettings = new MagickReadSettings
                    {
                        Format = MagickFormat.Png,
                    };

                    using (var input = new MagickImageCollection(Files.CirclePNG, readSettings))
                    {
                        using (var tempFile = new TemporaryFile(".jpg"))
                        {
                            input.Write(tempFile);

                            using (var output = new MagickImageCollection(tempFile))
                            {
                                Assert.Equal(MagickFormat.Jpeg, output[0].Format);
                            }
                        }
                    }
                }
コード例 #10
0
        static public Stream AsOneImageToStream(string fileName, MagickFormat imageExtension)
        {
            Stream stream = new MemoryStream();

            var settings = new MagickReadSettings();

            settings.Density = new Density(300);

            using (var images = new MagickImageCollection())
            {
                images.Read(fileName, settings);

                using (var vertical = images.AppendVertically())
                {
                    vertical.Format = imageExtension;
                    vertical.Write(stream);
                }
            }
            return(stream);
        }
コード例 #11
0
        private MagickImage CreateLinearTexture()
        {
            MagickImage gradient = new MagickImage("gradient:", Thickness, Thickness * 4);

            gradient.Rotate(270);

            MagickImage thick1 = CreateRolled(gradient, Thickness);
            MagickImage thick2 = CreateRolled(gradient, Thickness * 2);
            MagickImage thick3 = CreateRolled(gradient, Thickness * 3);

            using (MagickImageCollection images = new MagickImageCollection())
            {
                images.Add(gradient);
                images.Add(thick1);
                images.Add(thick2);
                images.Add(thick3);

                return(images.AppendVertically());
            }
        }
コード例 #12
0
        internal static void GenerateImagesFromPdf(FileInfo pdfFile, DirectoryInfo directoryToSaveImages)
        {
            var settings = new MagickReadSettings {
                Density = new Density(96, 96)
            };

            using (var images = new MagickImageCollection())
            {
                images.Read(pdfFile, settings);
                var page = 1;
                Console.WriteLine($"Saving generated image from pdf to {directoryToSaveImages.FullName}");

                foreach (var magickImage in images)
                {
                    var outputFile = new FileInfo(Path.Combine(directoryToSaveImages.FullName, pdfFile.Name + "_" + page + ".png"));
                    magickImage.Write(outputFile);
                    page++;
                }
            }
        }
コード例 #13
0
        public static void ReadSinglePageFromPDF()
        {
            using (MagickImageCollection collection = new MagickImageCollection())
            {
                MagickReadSettings settings = new MagickReadSettings();
                settings.FrameIndex = 0; // First page
                settings.FrameCount = 1; // Number of pages

                // Read only the first page of the pdf file
                collection.Read(SampleFiles.SnakewarePdf, settings);

                // Clear the collection
                collection.Clear();

                settings.FrameCount = 2; // Number of pages

                // Read the first two pages of the pdf file
                collection.Read(SampleFiles.SnakewarePdf, settings);
            }
        }
コード例 #14
0
        public static void ReadImageWithMultipleFrames()
        {
            // Read from file
            using (MagickImageCollection collection = new MagickImageCollection(SampleFiles.SnakewareJpg))
            {
            }

            // Read from stream
            using (MemoryStream memStream = LoadMemoryStreamImage())
            {
                using (MagickImageCollection collection = new MagickImageCollection(memStream))
                {
                }
            }

            // Read from byte array
            byte[] data = LoadImageBytes();
            using (MagickImageCollection collection = new MagickImageCollection(data))
            {
            }

            // Read pdf with custom density.
            MagickReadSettings settings = new MagickReadSettings();

            settings.Density = new Density(144);

            using (MagickImageCollection collection = new MagickImageCollection(SampleFiles.SnakewarePdf, settings))
            {
            }

            using (MagickImageCollection collection = new MagickImageCollection())
            {
                collection.Read(SampleFiles.SnakewareJpg);
                using (MemoryStream memStream = LoadMemoryStreamImage())
                {
                    collection.Read(memStream);
                }
                collection.Read(data);
                collection.Read(SampleFiles.SnakewarePdf, settings);
            }
        }
コード例 #15
0
        private void btnSplit_Click(object sender, EventArgs e)
        {
            DateTime           dt_start = System.DateTime.Now;
            MagickReadSettings settings = new MagickReadSettings();

            settings.Density = new MagickGeometry(300, 300);
            OpenFileDialog dlg = new OpenFileDialog();

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                string dbt_wfile     = dlg.FileName;
                string pdfFolderPath = Path.Combine(Path.GetDirectoryName(dbt_wfile),
                                                    Path.GetFileNameWithoutExtension(dbt_wfile));
                if (!Directory.Exists(pdfFolderPath))
                {
                    Directory.CreateDirectory(pdfFolderPath);
                }
                int count = NCPDF.CountPageNo(dbt_wfile);
                using (MagickImageCollection images = new MagickImageCollection())
                {
                    for (int idx = 0; idx < count; idx++)
                    {
                        string pdf_file = Path.Combine(pdfFolderPath, idx.ToString() + ".pdf");
                        NCPDF.ExtractPages(dbt_wfile, pdf_file, idx + 1, idx + 1);
                        images.Read(pdf_file, settings);

                        //int page = 0;
                        foreach (MagickImage image in images)
                        {
                            if (!File.Exists(pdfFolderPath + "\\image" + idx + ".jpg"))
                            {
                                image.Write(pdfFolderPath + "\\image" + idx + ".jpg");
                            }
                            //page++;
                        }
                        File.Delete(pdf_file);
                    }
                }
            }
            MessageBox.Show(DateTime.Now.Subtract(dt_start).Duration().Seconds.ToString());
        }
コード例 #16
0
        public void Test_Flatten()
        {
            using (IMagickImageCollection collection = new MagickImageCollection())
            {
                ExceptionAssert.Throws <InvalidOperationException>(delegate()
                {
                    collection.Flatten();
                });

                collection.Add(new MagickImage(MagickColors.Brown, 10, 10));
                IMagickImage center = new MagickImage(MagickColors.Fuchsia, 4, 4);
                center.Page = new MagickGeometry(3, 3, 4, 4);
                collection.Add(center);

                using (IMagickImage image = collection.Flatten())
                {
                    ColorAssert.AreEqual(MagickColors.Brown, image, 0, 0);
                    ColorAssert.AreEqual(MagickColors.Fuchsia, image, 5, 5);
                }
            }
        }
コード例 #17
0
ファイル: TheReadMethod.cs プロジェクト: junelin66/Magick.NET
                public void ShouldUseTheCorrectReaderWhenFormatIsSet()
                {
                    var bytes    = Encoding.ASCII.GetBytes("%PDF-");
                    var settings = new MagickReadSettings
                    {
                        Format = MagickFormat.Png,
                    };

                    using (MemoryStream stream = new MemoryStream(bytes))
                    {
                        using (var images = new MagickImageCollection())
                        {
                            var exception = Assert.Throws <MagickCorruptImageErrorException>(() =>
                            {
                                images.Read(stream, settings);
                            });

                            Assert.Contains("ReadPNGImage", exception.Message);
                        }
                    }
                }
コード例 #18
0
        public void Test_AdditionalInfo()
        {
            using (IMagickImageCollection images = new MagickImageCollection())
            {
                images.Read(Files.Coders.LayerStylesSamplePSD);

                CheckProfile(images[1], 264);

                var defines = new PsdWriteDefines()
                {
                    AdditionalInfo = PsdAdditionalInfo.All
                };
                WriteAndCheckProfile(images, defines, 264);

                defines.AdditionalInfo = PsdAdditionalInfo.Selective;
                WriteAndCheckProfile(images, defines, 152);

                defines.AdditionalInfo = PsdAdditionalInfo.None;
                WriteAndCheckProfile(images, defines, 0);
            }
        }
コード例 #19
0
        public void Test_Montage()
        {
            using (MagickImageCollection images = new MagickImageCollection())
            {
                for (int i = 0; i < 9; i++)
                {
                    images.Add(Files.Builtin.Logo);
                }

                MontageSettings ms = new MontageSettings();
                ms.Geometry     = new MagickGeometry(string.Format("{0}x{1}", 200, 200));
                ms.TileGeometry = new MagickGeometry(string.Format("{0}x", 2));

                using (MagickImage montageResult = images.Montage(ms))
                {
                    Assert.IsNotNull(montageResult);
                    Assert.AreEqual(400, montageResult.Width);
                    Assert.AreEqual(1000, montageResult.Height);
                }
            }
        }
コード例 #20
0
            public void ShouldMergeTheImages()
            {
                using (IMagickImageCollection collection = new MagickImageCollection())
                {
                    collection.Read(Files.RoseSparkleGIF);

                    using (IPixelCollection pixels = collection[1].GetPixels())
                    {
                        MagickColor color = pixels.GetPixel(53, 3).ToColor();
                        Assert.AreEqual(0, color.A);
                    }

                    collection.Coalesce();

                    using (IPixelCollection pixels = collection[1].GetPixels())
                    {
                        MagickColor color = pixels.GetPixel(53, 3).ToColor();
                        Assert.AreEqual(Quantum.Max, color.A);
                    }
                }
            }
コード例 #21
0
        /// <summary>
        /// Generates frames for .gif image
        /// </summary>
        /// <param name="imageCollection">Object for Stack Images</param>
        /// <param name="text">Text to be Draw</param>
        /// <param name="counter">Stack number</param>
        /// <returns></returns>
        public static MagickImageCollection FramesGeneration(MagickImageCollection imageCollection, string text, int counter)
        {
            Image          image     = null;
            ImageConverter converter = new ImageConverter();

            if (imageCollection == null)
            {
                imageCollection = new MagickImageCollection();
            }

            image = DrawText(text);
            byte[] buffer      = (byte[])converter.ConvertTo(image, typeof(byte[]));
            var    imageMagick = new MagickImage(buffer);

            imageCollection.Add(imageMagick);
            imageCollection[counter].AnimationDelay = 100;

            converter = null;

            return(imageCollection);
        }
コード例 #22
0
        private string GetTheGif(IndexViewModel model)
        {
            if (model == null || model.TheImages == null || model.TheImages.Count == 0)
            {
                return(null);
            }
            string imageBase64 = null;
            string webRootPath = _hostingEnvironment.WebRootPath;

            model.TheImages = OrderAndExtend(model.TheImages);

            using (MagickImageCollection frames = CreateFrameCollection(model))
            {
                // Save gif
                MemoryStream ms = new MemoryStream();
                frames.Write(ms, MagickFormat.Gif);
                imageBase64 = Convert.ToBase64String(ms.ToArray());
            }

            return(imageBase64);
        }
コード例 #23
0
            public void ShouldMakeSetWhichAdditionalInfoShouldBeWritten()
            {
                using (var images = new MagickImageCollection())
                {
                    images.Read(Files.Coders.LayerStylesSamplePSD);

                    CheckProfile(images[1], 264);

                    var defines = new PsdWriteDefines
                    {
                        AdditionalInfo = PsdAdditionalInfoPart.All,
                    };
                    WriteAndCheckProfile(images, defines, 264);

                    defines.AdditionalInfo = PsdAdditionalInfoPart.Selective;
                    WriteAndCheckProfile(images, defines, 152);

                    defines.AdditionalInfo = PsdAdditionalInfoPart.None;
                    WriteAndCheckProfile(images, defines, 0);
                }
            }
コード例 #24
0
        public override void ExportVignette(Context context, string outputDir)
        {
            var s = context.Deserializer;

            var vignetteLists = new string[] { "intro", "outro" };

            foreach (var p in vignetteLists)
            {
                var vigPath = p + ".dat";

                if (!context.FileExists(vigPath))
                {
                    continue;
                }

                var vigListFile = FileFactory.Read <LUDI_PocketPC_DataFile>(vigPath, context);
                s.DoAt(vigListFile.Resolve(1), () =>
                {
                    using (MagickImageCollection collection = new MagickImageCollection())
                    {
                        var video = s.SerializeObject <LUDI_Video>(default, name: p);
コード例 #25
0
        public void Test_Write()
        {
            long fileSize;

            using (IMagickImage image = new MagickImage(Files.RoseSparkleGIF))
            {
                fileSize = image.FileSize;
            }

            Assert.AreEqual(fileSize, 9891);

            using (IMagickImageCollection collection = new MagickImageCollection(Files.RoseSparkleGIF))
            {
                using (MemoryStream memStream = new MemoryStream())
                {
                    collection.Write(memStream);

                    Assert.AreEqual(fileSize, memStream.Length);
                }
            }

            FileInfo tempFile = new FileInfo(Path.GetTempFileName() + ".gif");

            try
            {
                using (IMagickImageCollection collection = new MagickImageCollection(Files.RoseSparkleGIF))
                {
                    collection.Write(tempFile);

                    Assert.AreEqual(fileSize, tempFile.Length);
                }
            }
            finally
            {
                if (tempFile.Exists)
                {
                    tempFile.Delete();
                }
            }
        }
コード例 #26
0
        public void Test_OptimizePlus()
        {
            using (IMagickImageCollection collection = new MagickImageCollection())
            {
                ExceptionAssert.Throws <InvalidOperationException>(() =>
                {
                    collection.OptimizePlus();
                });

                collection.Add(new MagickImage(MagickColors.Red, 11, 11));

                /* the second image will not be removed if it is a duplicate so we
                 * need to add an extra one. */
                collection.Add(new MagickImage(MagickColors.Red, 11, 11));
                collection.Add(new MagickImage(MagickColors.Red, 11, 11));

                IMagickImage image = new MagickImage(MagickColors.Red, 11, 11);
                using (var pixels = image.GetPixels())
                {
                    pixels.SetPixel(5, 5, new QuantumType[] { 0, Quantum.Max, 0 });
                }

                collection.Add(image);
                collection.OptimizePlus();

                Assert.AreEqual(3, collection.Count);

                Assert.AreEqual(1, collection[1].Width);
                Assert.AreEqual(1, collection[1].Height);
                Assert.AreEqual(-1, collection[1].Page.X);
                Assert.AreEqual(-1, collection[1].Page.Y);
                ColorAssert.AreEqual(MagickColors.Red, collection[1], 0, 0);

                Assert.AreEqual(1, collection[2].Width);
                Assert.AreEqual(1, collection[2].Height);
                Assert.AreEqual(5, collection[2].Page.X);
                Assert.AreEqual(5, collection[2].Page.Y);
                ColorAssert.AreEqual(MagickColors.Lime, collection[2], 0, 0);
            }
        }
コード例 #27
0
ファイル: CloudOcrService.cs プロジェクト: redwards510/OCRina
        public static FileInfo ConvertPdfToPng(FileInfo pdfFile)
        {
            if (pdfFile.DirectoryName == null)
            {
                throw new ArgumentException("file directory was null. why?");
            }

            MagickReadSettings imsettings = new MagickReadSettings
            {
                Density    = new PointD(300, 300), // Settings the density to 300 dpi will create an image with a better quality
                FrameIndex = 0,                    // first page
                FrameCount = 1,                    // number of pages
                Format     = MagickFormat.Pdf
            };

            const MagickFormat imageOutputFormat = MagickFormat.Png;
            var pngFilename = GetFileNameWithoutExtension(pdfFile) + "." + imageOutputFormat.ToString();
            var pngFile     = new FileInfo(Path.Combine(pdfFile.DirectoryName, pngFilename));

            try
            {
                // note that this "collection" is a bunch of pages in a pdf, and actually only 1 because we are limiting it to page 1.
                using (var images = new MagickImageCollection())
                {
                    // Add all the pages of the pdf file to the collection
                    images.Read(pdfFile, imsettings);
                    foreach (var image in images)
                    {
                        image.Format = imageOutputFormat;
                        image.Write(pngFile);
                    }
                }
                return(pngFile);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
                throw;
            }
        }
コード例 #28
0
        public static void Process(string path)
        {
            var filename = Path.GetFileNameWithoutExtension(path);

            if (path.Contains(".gif"))
            {
                using (MagickImage image = new MagickImage(path))
                {
                    // Save frame as jpg
                    image.Write("/Images/results/" + filename + ".jpg");
                }
            }
            else if (path.Contains(".pdf"))
            {
                MagickReadSettings settings = new MagickReadSettings();
                // Settings the density to 150 dpi will create an image with a better quality
                settings.Density = new Density(150, 150);

                using (MagickImageCollection images = new MagickImageCollection())
                {
                    // Add all the pages of the pdf file to the collection
                    images.Read(path, settings);

                    int page = 1;
                    foreach (MagickImage image in images)
                    {
                        // Write page to file that contains the page number
                        image.Write("/Images/results/" + filename + ".Page" + page + ".png");
                        // Writing to a specific format works the same as for a single image
                        image.Format = MagickFormat.Tif;
                        image.Write("/Images/results/" + filename + ".Page" + page + ".tif");
                        page++;
                    }
                }
            }
            else
            {
                throw new NotImplementedException("File type not supported");
            }
        }
コード例 #29
0
        /// <summary>
        /// Load the given page from the PDF
        /// </summary>
        /// <param name="pageNumber">Page number to load</param>
        /// <returns>Bitmap representing page</returns>
        protected override async Task <Bitmap> LoadPage(int pageNumber)
        {
            using (var collection = new MagickImageCollection())
            {
                using (var stream = new MemoryStream())
                {
                    return(await Task.Run(() =>
                    {
                        var settings = new MagickReadSettings();

                        // Page to read
                        settings.FrameIndex = pageNumber;

                        // Number of pages to read
                        settings.FrameCount = 1;

                        // This is currently just a "best guess" at the proper density to read the image at
                        // There wasn't an obvious way to get the actual density of the screen from Avalonia
                        settings.Density = new Density(200);

                        // Read only the given page of the pdf file
                        collection.Read(base.FilePath, settings);
                        var img = collection[0];

                        // Write a PNG to a stream, then pass that to an Avalonia Bitmap
                        img.Write(stream, MagickFormat.Png);
                        stream.Position = 0;
                        var bitmap = new Bitmap(stream);

                        // Clear the collection
                        collection.Clear();

                        return Task.FromResult(bitmap);
                    }));
                }
            }

            throw new System.Exception("Error loading page from PDF " + FilePath);
        }
コード例 #30
0
        private static byte[] ProcessGif(int requestWidth, int requestHeight, int quality, byte[] bytes, string options)
        {
            using (MagickImageCollection collection = new MagickImageCollection(bytes))
            {
                collection.Coalesce();

                // the height will be calculated with the aspect ratio.
                foreach (var magickImage in collection)
                {
                    var gifImage = (MagickImage)magickImage;
                    ResizeImage(requestWidth, requestHeight, quality, options, gifImage);
                }

                collection.RePage();

                collection.Optimize();
                collection.OptimizeTransparency();

                // Save the result
                return(collection.ToByteArray());
            }
        }
コード例 #31
0
        public void ConvertToScanned(string filename)
        {
            MagickReadSettings settings = new MagickReadSettings
            {
                Density = new Density(300, 300)
            };

            MagickNET.SetGhostscriptDirectory(Path.GetDirectoryName(GhostScriptHelper.GetGhostscriptVersion().DllPath));

            List <string> scannedimgfiles = new List <string>();

            using (MagickImageCollection images = new MagickImageCollection())
            {
                images.Read(filename, settings);

                int page = 1;

                foreach (MagickImage image in images)
                {
                    image.ColorSpace = ColorSpace.Gray;
                    var clone = image.Clone();
                    clone.Blur(0, 1);
                    clone.Compose = CompositeOperator.DivideDst;
                    image.Composite(clone);
                    image.LinearStretch(new Percentage(5), new Percentage(0));
                    image.Rotate(0.2);

                    var tempimgpath = Path.GetTempPath() + Path.GetFileNameWithoutExtension(filename) + "_img_" + page + ".png";
                    image.Write(tempimgpath);
                    scannedimgfiles.Add(tempimgpath);

                    page++;
                }
            }

            new ITextHelper().ImageToPdf(scannedimgfiles, filename);

            scannedimgfiles.ForEach(f => File.Delete(f));
        }
コード例 #32
0
        public void Test_Morph()
        {
            using (IMagickImageCollection collection = new MagickImageCollection())
            {
                ExceptionAssert.Throws <InvalidOperationException>(delegate()
                {
                    collection.Morph(10);
                });

                collection.Add(Files.Builtin.Logo);

                ExceptionAssert.Throws <InvalidOperationException>(delegate()
                {
                    collection.Morph(10);
                });

                collection.AddRange(Files.Builtin.Wizard);

                collection.Morph(4);
                Assert.AreEqual(6, collection.Count);
            }
        }
コード例 #33
0
            public void ShouldCorrectlyOptimizeTheImages()
            {
                using (IMagickImageCollection collection = new MagickImageCollection())
                {
                    collection.Add(new MagickImage(MagickColors.Red, 11, 11));

                    var image = new MagickImage(MagickColors.Red, 11, 11);
                    using (var pixels = image.GetPixels())
                    {
                        pixels.SetPixel(5, 5, new QuantumType[] { 0, Quantum.Max, 0 });
                    }

                    collection.Add(image);
                    collection.Optimize();

                    Assert.AreEqual(1, collection[1].Width);
                    Assert.AreEqual(1, collection[1].Height);
                    Assert.AreEqual(5, collection[1].Page.X);
                    Assert.AreEqual(5, collection[1].Page.Y);
                    ColorAssert.AreEqual(MagickColors.Lime, collection[1], 0, 0);
                }
            }
コード例 #34
0
ファイル: SpoilersService.cs プロジェクト: Slamerz/DmC
 public Task <MagickImageCollection> SpoilerImg(string uri) => Task.Run(async() =>
 {
     //load image
     var img2 = await DownloadImageAsync(uri);
     //create spoiler warning image
     Image <Rgba32> img1 = new Image <Rgba32>(img2.Width, img2.Height);
     _Spoil    = _fonts.Find("Whitney-Bold").CreateFont(img2.Width * 0.064f);
     var fill  = Brushes.Solid <Rgba32>(Rgba32.Black);
     var brush = Brushes.Solid <Rgba32>(Rgba32.White);
     var rect  = new Rectangle(0, 0, img2.Width, img2.Height);
     img1.BackgroundColor(Rgba32.Black, rect);
     img1.DrawText("Spoiler Warning" + "\r\n" + "(Mouse over to view)", _Spoil, brush, new PointF(10, 10), new TextGraphicsOptions(true)
     {
         WrapTextWidth = img1.Width - 20
     });
     MagickImage f1       = new MagickImage(img1.ToStream());
     MagickImage f2       = new MagickImage(img2.ToStream());
     MagickImage[] frames = { f1, f2 };
     var gifs             = GetGif(frames);
     var gif = new MagickImageCollection(gifs);
     return(gif);
 });
コード例 #35
0
		public void Test_Append()
		{
			int width = 70;
			int height = 46;

			using (MagickImageCollection collection = new MagickImageCollection(Files.RoseSparkleGIF))
			{
				Assert.AreEqual(width, collection[0].Width);
				Assert.AreEqual(height, collection[0].Height);

				using (MagickImage image = collection.AppendHorizontally())
				{
					Assert.AreEqual(width * 3, image.Width);
					Assert.AreEqual(height, image.Height);
				}

				using (MagickImage image = collection.AppendVertically())
				{
					Assert.AreEqual(width, image.Width);
					Assert.AreEqual(height * 3, image.Height);
				}
			}
		}
コード例 #36
0
		public void Test_Reverse()
		{
			using (MagickImageCollection collection = new MagickImageCollection(Files.RoseSparkleGIF))
			{
				MagickImage first = collection.First();
				collection.Reverse();

				MagickImage last = collection.Last();
				Assert.IsTrue(last == first);
			}
		}
コード例 #37
0
		public void Test_Write()
		{
			long fileSize;
			using (MagickImage image = new MagickImage(Files.RoseSparkleGIF))
			{
				fileSize = image.FileSize;
			}

			using (MagickImageCollection collection = new MagickImageCollection(Files.RoseSparkleGIF))
			{
				using (MemoryStream memStream = new MemoryStream())
				{
					collection.Write(memStream);

					Assert.AreEqual(fileSize, memStream.Length);
				}
			}
		}
コード例 #38
0
		public void Test_Index()
		{
			using (MagickImageCollection collection = new MagickImageCollection(Files.RoseSparkleGIF))
			{
				for (int i = 0; i < collection.Count; i++)
				{
					collection[i].Scale(35, 23);
					Assert.AreEqual(35, collection[i].Width);

					collection[i] = collection[i];
					Assert.AreEqual(35, collection[i].Width);

					collection[i] = null;
				}
			}
		}
コード例 #39
0
		public void Test_Dispose()
		{
			MagickImage image = new MagickImage(Color.Red, 10, 10);

			MagickImageCollection collection = new MagickImageCollection();
			collection.Add(image);
			collection.Dispose();

			Assert.AreEqual(0, collection.Count);
			image.Wave();
		}
コード例 #40
0
		public void Test_RePage()
		{
			using (MagickImageCollection collection = new MagickImageCollection(Files.RoseSparkleGIF))
			{
				collection[0].Page = new MagickGeometry("0x0+10+10");

				Assert.AreEqual(10, collection[0].Page.X);
				Assert.AreEqual(10, collection[0].Page.Y);

				collection.RePage();

				Assert.AreEqual(0, collection[0].Page.X);
				Assert.AreEqual(0, collection[0].Page.Y);
			}
		}
コード例 #41
0
		public void Test_CopyTo()
		{
			using (MagickImageCollection collection = new MagickImageCollection())
			{
				collection.Add(new MagickImage(Files.SnakewarePNG));
				collection.Add(new MagickImage(Files.RoseSparkleGIF));

				MagickImage[] images = new MagickImage[collection.Count];
				collection.CopyTo(images, 0);

				Assert.AreEqual(collection[0], images[0]);
				Assert.AreNotEqual(collection[0], images[1]);

				collection.CopyTo(images, 1);
				Assert.AreEqual(collection[0], images[0]);
				Assert.AreEqual(collection[0], images[1]);

				images = new MagickImage[collection.Count + 1];
				collection.CopyTo(images, 0);

				images = new MagickImage[1];
				collection.CopyTo(images, 0);

				ExceptionAssert.Throws<ArgumentNullException>(delegate()
				{
					collection.CopyTo(null, -1);
				});

				ExceptionAssert.Throws<ArgumentOutOfRangeException>(delegate()
				{
					collection.CopyTo(images, -1);
				});

			}
		}
コード例 #42
0
		public void Test_Remove()
		{
			using (MagickImageCollection collection = new MagickImageCollection(Files.RoseSparkleGIF))
			{
				MagickImage first = collection[0];
				collection.Remove(first);

				Assert.AreEqual(2, collection.Count);
				Assert.AreEqual(-1, collection.IndexOf(first));

				first = collection[0];
				collection.RemoveAt(0);

				Assert.AreEqual(1, collection.Count);
				Assert.AreEqual(-1, collection.IndexOf(first));
			}
		}
コード例 #43
0
		public void Test_ToBitmap()
		{
			using (MagickImageCollection collection = new MagickImageCollection(Files.RoseSparkleGIF))
			{
				Assert.AreEqual(3, collection.Count);

				Bitmap bitmap = collection.ToBitmap();
				Assert.IsNotNull(bitmap);
				Assert.AreEqual(3, bitmap.GetFrameCount(FrameDimension.Page));
			}
		}
コード例 #44
0
		public void Test_Morph()
		{
			using (MagickImageCollection collection = new MagickImageCollection(Files.RoseSparkleGIF))
			{
				Assert.AreEqual(3, collection.Count);

				using (MagickImageCollection morphed = collection.Morph(2))
				{
					Assert.AreEqual(7, morphed.Count);
				}
			}
		}
コード例 #45
0
		public void Test_Read()
		{
			MagickImageCollection collection = new MagickImageCollection();

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

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

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

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

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

			collection.Read(File.ReadAllBytes(Files.RoseSparkleGIF));
			Assert.AreEqual(3, collection.Count);

			using (FileStream fs = File.OpenRead(Files.RoseSparkleGIF))
			{
				collection.Read(fs);
				Assert.AreEqual(3, collection.Count);
			}

			collection.Read(Files.RoseSparkleGIF);
			Assert.AreEqual(3, collection.Count);

			collection.Dispose();
		}