当前位置: 首页>>代码示例>>C#>>正文


C# MagickImageCollection.Add方法代码示例

本文整理汇总了C#中ImageMagick.MagickImageCollection.Add方法的典型用法代码示例。如果您正苦于以下问题:C# MagickImageCollection.Add方法的具体用法?C# MagickImageCollection.Add怎么用?C# MagickImageCollection.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ImageMagick.MagickImageCollection的用法示例。


在下文中一共展示了MagickImageCollection.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateAnimatedGif

    public static void CreateAnimatedGif()
    {
      using (MagickImageCollection collection = new MagickImageCollection())
      {
        // Add first image and set the animation delay to 100ms
        collection.Add(SampleFiles.SnakewarePng);
        collection[0].AnimationDelay = 100;

        // Add second image, set the animation delay to 100ms and flip the image
        collection.Add(SampleFiles.SnakewarePng);
        collection[1].AnimationDelay = 100;
        collection[1].Flip();

        // Optionally reduce colors
        QuantizeSettings settings = new QuantizeSettings();
        settings.Colors = 256;
        collection.Quantize(settings);

        // Optionally optimize the images (images should have the same size).
        collection.Optimize();

        // Save gif
        collection.Write(SampleFiles.OutputDirectory + "Snakeware.Animated.gif");
      }
    }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:25,代码来源:CombiningImages.cs

示例2: CreatePallete

    private MagickImage CreatePallete()
    {
      using (MagickImageCollection images = new MagickImageCollection())
      {
        images.Add(new MagickImage(MagickColors.Red, 1, 1));
        images.Add(new MagickImage(MagickColors.Blue, 1, 1));
        images.Add(new MagickImage(MagickColors.Green, 1, 1));

        return images.AppendHorizontally();
      }
    }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:11,代码来源:MagickImageTests.cs

示例3: CreatePDFFromTwoImages

    public static void CreatePDFFromTwoImages()
    {
      using (MagickImageCollection collection = new MagickImageCollection())
      {
        // Add first page
        collection.Add(new MagickImage(SampleFiles.SnakewareJpg));
        // Add second page
        collection.Add(new MagickImage(SampleFiles.SnakewareJpg));

        // Create pdf file with two pages
        collection.Write(SampleFiles.OutputDirectory + "Snakeware.pdf");
      }
    }
开发者ID:levesque,项目名称:Magick.NET,代码行数:13,代码来源:ConvertPDF.cs

示例4: CombineScreenshot

        /// <summary>
        /// Combines the screenshots into one contiguous screenshot
        /// </summary>
        /// <param name="files">The files (images) to combine</param>
        /// <param name="e">For UX, an output progress message</param>
        public static void CombineScreenshot(FileSystemInfo[] files, WaitWindowEventArgs e)
        {
           

            string screenshotLocation = Path.Combine(Constants.CacheLocation, "temp.png");

            using (MagickImageCollection images = new MagickImageCollection())
            {
                // Add the first image
                var orderedFiles = files.OrderBy(f => f.CreationTime);
                foreach (FileSystemInfo file in orderedFiles)
                {
                    MagickImage first = new MagickImage(file.FullName);
                    e.Window.Message = "Obtaining Snapshots... Please Wait";
                    images.Add(first);
                }

                using (MagickImage result = images.AppendVertically())
                {
                    e.Window.Message = "Building Screenshot... Please Wait" + System.Environment.NewLine + "This can take a minute.";
                    try
                    {
                        result.Write(screenshotLocation);
                    } catch (MagickImageErrorException err)
                    {
                        Debug.WriteLine($"Error: {err}");
                    }
                   
                }
        
            }
        }
开发者ID:joe-williams-cccu,项目名称:OSIRTv2,代码行数:37,代码来源:ScreenshotHelper.cs

示例5: MergeMultipleImages

    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 (MagickImage result = images.Mosaic())
        {
          // Save the result
          result.Write(SampleFiles.OutputDirectory + "Mosaic.png");
        }
      }
    }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:20,代码来源:CombiningImages.cs

示例6: CreateIconFromPngFilesFromSvg

 public void CreateIconFromPngFilesFromSvg(IconInfo iconInfo)
 {
     if (iconInfo.NeedUpdate())
     {
         using (var imageCollection = new MagickImageCollection())
         {
             foreach (var iconInfoPngFile in iconInfo.PngFiles)
             {
                 var image = new MagickImage(iconInfoPngFile.FullName);
                 imageCollection.Add(image);
             }
             imageCollection.Write(iconInfo.IconFile.FullName);
         }
     }            
 }
开发者ID:trondr,项目名称:NMultiTool,代码行数:15,代码来源:ImageMagicProvider.cs

示例7: Test_Montage

    public void Test_Montage()
    {
      using (MagickImageCollection collection = new MagickImageCollection())
      {
        MontageSettings settings = new MontageSettings();
        settings.Geometry = new MagickGeometry(string.Format("{0}x{1}", 200, 200));
        settings.TileGeometry = new MagickGeometry(string.Format("{0}x", 2));

        ExceptionAssert.Throws<InvalidOperationException>(delegate ()
        {
          collection.Montage(settings);
        });

        for (int i = 0; i < 9; i++)
          collection.Add(Files.Builtin.Logo);

        using (MagickImage montageResult = collection.Montage(settings))
        {
          Assert.IsNotNull(montageResult);
          Assert.AreEqual(400, montageResult.Width);
          Assert.AreEqual(1000, montageResult.Height);
        }
      }
    }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:24,代码来源:MagickImageCollectionTests.cs

示例8: Test_Map

    public void Test_Map()
    {
      using (MagickImageCollection colors = new MagickImageCollection())
      {
        colors.Add(new MagickImage(MagickColors.Red, 1, 1));
        colors.Add(new MagickImage(MagickColors.Green, 1, 1));

        using (MagickImage remapImage = colors.AppendHorizontally())
        {
          using (MagickImageCollection collection = new MagickImageCollection())
          {
            ExceptionAssert.Throws<InvalidOperationException>(delegate ()
            {
              collection.Map(null);
            });

            ExceptionAssert.Throws<InvalidOperationException>(delegate ()
            {
              collection.Map(remapImage);
            });

            collection.Read(Files.RoseSparkleGIF);

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

            QuantizeSettings settings = new QuantizeSettings();
            settings.DitherMethod = DitherMethod.FloydSteinberg;

            collection.Map(remapImage, settings);

            ColorAssert.AreEqual(MagickColors.Red, collection[0], 60, 17);
            ColorAssert.AreEqual(MagickColors.Green, collection[0], 37, 24);

            ColorAssert.AreEqual(MagickColors.Red, collection[1], 58, 30);
            ColorAssert.AreEqual(MagickColors.Green, collection[1], 36, 26);

            ColorAssert.AreEqual(MagickColors.Red, collection[2], 60, 40);
            ColorAssert.AreEqual(MagickColors.Green, collection[2], 17, 21);
          }
        }
      }
    }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:45,代码来源:MagickImageCollectionTests.cs

示例9: Test_Flatten

    public void Test_Flatten()
    {
      using (MagickImageCollection collection = new MagickImageCollection())
      {
        ExceptionAssert.Throws<InvalidOperationException>(delegate ()
        {
          collection.Flatten();
        });

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

        using (MagickImage image = collection.Flatten())
        {
          ColorAssert.AreEqual(MagickColors.Brown, image, 0, 0);
          ColorAssert.AreEqual(MagickColors.Fuchsia, image, 5, 5);
        }
      }
    }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:21,代码来源:MagickImageCollectionTests.cs

示例10: Main

        static void Main(string[] args)
        {
            string searchQuery = System.Windows.Forms.Clipboard.GetText();

            using (MagickImageCollection animation = new MagickImageCollection())  //Very few cartoons are broadcast live it's a terrible strain on the animators wrist.
            using (WebClient wc = new WebClient())                                  //The Internet, eh?
            {
                //Check the query
                List<a_lengthly_inefficient_search_at_the_taxpayers_expense>  searchResult
                    = JsonConvert.DeserializeObject<List<a_lengthly_inefficient_search_at_the_taxpayers_expense>>
                    (wc.DownloadString(Frinkiac.API_Root + "search?q=" + searchQuery.Replace(" ", "%20")));
                if (searchResult.Count <= resultIndex)      //Bad grammar overload.
                    throw new IndexOutOfRangeException("search string " + searchQuery + " not found");

                //Retrieve captions associated with result
                childrens_letters_to_god captionResult = JsonConvert.DeserializeObject<childrens_letters_to_god>(wc.DownloadString(Frinkiac.API_Root
                    + "caption?e=" + searchResult[resultIndex].Episode 
                    + "&t=" + searchResult[resultIndex].Timestamp));
                
                while (frameBatches > 0)
                {
                    foreach (an_arm_drawn_by_nobody_it_is_worth_nothing frame in captionResult.Neighboreenos)
                    {   //request each frame in captionQuery and add to our MagickImageCollection for the animation
                        MagickImage frameImage = new MagickImage(wc.DownloadData(Frinkiac.IMG_Root
                            + frame.Episode + "/"
                            + frame.Timestamp + ".jpg"), new MagickReadSettings());

                        frameImage.AnimationDelay = 20;

                        foreach (Anifrinkiac.you_egghead_writers_wouldve_never_thought_of_it caption in captionResult.Subtitles)       //Check out the subtitle results
                            if ((frame.Timestamp > caption.StartTimestamp)
                             && (frame.Timestamp < caption.EndTimestamp))
                                frameImage.Annotate(caption.Content, Gravity.South);    //Apply captions

                        animation.Add(frameImage);
                    }                     //Retrieve the next set of frames
                    if (frameBatches-- > 0)
                    {
                        captionResult = JsonConvert.DeserializeObject<childrens_letters_to_god>(wc.DownloadString(Frinkiac.API_Root
                    + "caption?e=" + searchResult[resultIndex].Episode
                    + "&t=" + captionResult.Neighboreenos[captionResult.Neighboreenos.Count - 1].Timestamp));
                        //Do it again for all new frames
                        captionResult = JsonConvert.DeserializeObject<childrens_letters_to_god>(wc.DownloadString(Frinkiac.API_Root
                            + "caption?e=" + searchResult[resultIndex].Episode
                            + "&t=" + captionResult.Neighboreenos[captionResult.Neighboreenos.Count - 1].Timestamp)); 
                    }
                }

                // Optionally reduce colors
                QuantizeSettings settings = new QuantizeSettings();
                settings.Colors = 256;
                animation.Quantize(settings);
                // Optionally optimize the images (images should have the same size).
                animation.Optimize();
                //Upload gif to imgur
                wc.Headers.Add("Authorization", "Client-ID " +  System.Configuration.ConfigurationManager.AppSettings["imgurClientID"].ToString());
                NameValueCollection values = new NameValueCollection
                    {
                        { "image", Convert.ToBase64String(animation.ToByteArray(MagickFormat.Gif)) }
                    };
                //Deserialize the xml reply
                XDocument reply = XDocument.Load(new MemoryStream(wc.UploadValues("https://api.imgur.com/3/upload.xml", values)));

                //Give up the goods
                System.Console.WriteLine(reply.Root.Element("link"));
                System.Windows.Forms.Clipboard.SetText(reply.Root.Element("link").Value + " : " + searchQuery);

            }
            
        }
开发者ID:tummyacid,项目名称:VS2015,代码行数:70,代码来源:Program.cs

示例11: ImageProcessing

        // Load images from twitter, process them into collage
        string ImageProcessing(List<string> urls, int size, List<int> counts, bool resize)
        {
            byte[] imageByteData = null;
            byte[] data = null;
            // Load images into collection
            using (MagickImageCollection collection = new MagickImageCollection())
            {
                
                for (int i = 0; i < urls.Count; i++)
                {
                    imageByteData = new System.Net.WebClient().DownloadData(urls[i]);
                    MagickImage tmpImage = new MagickImage(imageByteData);
                    collection.Add(tmpImage);
                }
                // generade byte array for collage from images collection
                if (resize)
                {
                    // collage with proportional images
                    SizableImages simages = new SizableImages(counts);
                    List<SizableImage> arrangedImages = simages.GetImages();
                    int width = simages.GetXBottom() - simages.GetXTop();
                    int height = simages.GetYBottom() - simages.GetYTop();

                    int maxDimension;

                    if (width < height)
                    {
                        maxDimension = height;
                    }
                    else
                    {
                        maxDimension = width;
                    }

                    double correction = (double)size / maxDimension;


                    MagickReadSettings settings = new MagickReadSettings();
                    settings.Width = (int)(width * correction);
                    settings.Height = (int)(height * correction);
                    using (MagickImage image = new MagickImage("xc:white", settings))
                    {
                        for (int i = 0; i < arrangedImages.Count(); i++)
                        {
                            collection[
                                arrangedImages[i].id
                                ].Resize(new MagickGeometry((int)(arrangedImages[i].size * correction)));
                            image.Composite(collection[arrangedImages[i].id],
                                (int)(arrangedImages[i].positionX * correction),
                                (int)(arrangedImages[i].positionY * correction));
                        }
                        image.Format = MagickFormat.Png;
                        data = image.ToByteArray();
                    }
                }
                else
                {
                    // collage with single sized images
                    data = GenerateCollage(collection, size);
                }
            }
            // convert byte array to data url
            string imageBase64Data = Convert.ToBase64String(data/*imageByteData*/);
            string imageDataURL = string.Format("data:image/png;base64,{0}", imageBase64Data);
            return imageDataURL;
        }
开发者ID:litoshko,项目名称:Twitter-Collage,代码行数:67,代码来源:HomeController.cs

示例12: Test_Quantize

    public void Test_Quantize()
    {
      using (MagickImageCollection collection = new MagickImageCollection())
      {
        ExceptionAssert.Throws<InvalidOperationException>(delegate ()
        {
          collection.Quantize();
        });

        collection.Add(Files.FujiFilmFinePixS1ProJPG);

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

        QuantizeSettings settings = new QuantizeSettings();
        settings.Colors = 3;

        MagickErrorInfo errorInfo = collection.Quantize(settings);
        Assert.IsNull(errorInfo);

#if Q8
        ColorAssert.AreEqual(new MagickColor("#2b414f"), collection[0], 66, 115);
        ColorAssert.AreEqual(new MagickColor("#7b929f"), collection[0], 179, 123);
        ColorAssert.AreEqual(new MagickColor("#44739f"), collection[0], 188, 135);
#elif Q16 || Q16HDRI
        ColorAssert.AreEqual(new MagickColor("#447073169f39"), collection[0], 66, 115);
        ColorAssert.AreEqual(new MagickColor("#7b4292c29f25"), collection[0], 179, 123);
        ColorAssert.AreEqual(new MagickColor("#2aef41654efc"), collection[0], 188, 135);
#else
#error Not implemented!
#endif
      }
    }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:35,代码来源:MagickImageCollectionTests.cs

示例13: Test_OptimizePlus

    public void Test_OptimizePlus()
    {
      using (MagickImageCollection collection = new MagickImageCollection())
      {
        ExceptionAssert.Throws<InvalidOperationException>(delegate ()
        {
          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));

        MagickImage image = new MagickImage(MagickColors.Red, 11, 11);
        using (var pixels = image.GetPixels())
        {
          pixels.Set(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);
      }
    }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:38,代码来源:MagickImageCollectionTests.cs

示例14: Test_Clone

    public void Test_Clone()
    {
      using (MagickImageCollection collection = new MagickImageCollection())
      {
        collection.Add(Files.Builtin.Logo);
        collection.Add(Files.Builtin.Rose);
        collection.Add(Files.Builtin.Wizard);

        using (MagickImageCollection clones = collection.Clone())
        {
          Assert.AreEqual(collection[0], clones[0]);
          Assert.AreEqual(collection[1], clones[1]);
          Assert.AreEqual(collection[2], clones[2]);
        }
      }
    }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:16,代码来源:MagickImageCollectionTests.cs

示例15: Test_Montage

    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);
        }
      }
    }
开发者ID:levesque,项目名称:Magick.NET,代码行数:19,代码来源:MagickImageCollectionTests.cs


注:本文中的ImageMagick.MagickImageCollection.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。