Ejemplo n.º 1
3
    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");
      }
    }
Ejemplo n.º 2
0
    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();
      }
    }
Ejemplo n.º 3
0
    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");
      }
    }
Ejemplo n.º 4
0
    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");
        }
      }
    }
Ejemplo n.º 5
0
 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);
         }
     }            
 }
Ejemplo n.º 6
0
        private IMagickImage Execute(XmlElement element, MagickImageCollection collection)
        {
            if (element.Name == "read")
            {
                collection.Add(CreateMagickImage(element));
                return(null);
            }

            if (element.Name == "write")
            {
                string fileName_ = XmlHelper.GetAttribute <string>(element, "fileName");
                collection.Write(fileName_);
                return(null);
            }

            return(ExecuteCollection(element, collection));
        }
        public override void ConfigGA(GeneticAlgorithm ga)
        {
            base.ConfigGA(ga);
            ga.MutationProbability = 0.4f;
            ga.TerminationReached += (sender, args) =>
            {
                using (var collection = new MagickImageCollection())
                {
                    var files = Directory.GetFiles(m_destFolder, "*.png");

                    foreach (var image in files)
                    {
                        collection.Add(image);
                        collection[0].AnimationDelay = 100;
                    }

                    var settings = new QuantizeSettings();
                    settings.Colors = 256;
                    collection.Quantize(settings);

                    collection.Optimize();
                    collection.Write(Path.Combine(m_destFolder, "result.gif"));
                }
            };
        }
    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);
        }
      }
    }
Ejemplo n.º 9
0
 /*
  * Create gif for this test packa4
  * If there are more pics than the max (250), set the skip value slightly higher to skip extra images
  */
 public void createGif()
 {
     if (this.pngToGifFiles == null || this.pd == null) return;
     Console.WriteLine("[i] Creating gif for task " + this.taskIDNum);
     using (MagickImageCollection pngs = new MagickImageCollection())
     {
         int skip = 1, maxPics = 250, extraPics;
         if ((extraPics = pngToGifFiles.Length - maxPics) > 1) skip = (int)Math.Ceiling((double)pngToGifFiles.Length / maxPics);
         for (int i = 0, count = 0; i < pngToGifFiles.Length; i += skip)
         {
             pngs.Add(pngToGifFiles[i]);
             pngs[count++].AnimationDelay = 10;
         }
         pngs[0].AnimationIterations = 1;
         QuantizeSettings sett = new QuantizeSettings();
         sett.Colors = 256;
         pngs.Quantize(sett);
         pngs.Optimize();
         pngs.Write(this.pd + "install_" + this.taskIDNum + ".gif");
         foreach (string fileToDelete in this.pngToGifFiles) File.Delete(fileToDelete); // Delete the extra .png files
         Console.WriteLine("[\u221A] Gif created for task " + this.taskIDNum + ".");
     } // end pngs using
 }
    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);
          }
        }
      }
    }
    public void Test_Dispose()
    {
      MagickImage image = new MagickImage(MagickColors.Red, 10, 10);

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

      Assert.AreEqual(0, collection.Count);
      ExceptionAssert.Throws<ObjectDisposedException>(delegate ()
      {
        image.Flip();
      });
    }
Ejemplo n.º 12
0
        // 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;
        }
    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
      }
    }
    public void Test_TrimBounds()
    {
      using (MagickImageCollection collection = new MagickImageCollection())
      {
        ExceptionAssert.Throws<InvalidOperationException>(delegate ()
        {
          collection.TrimBounds();
        });

        collection.Add(Files.Builtin.Logo);
        collection.Add(Files.Builtin.Wizard);
        collection.TrimBounds();

        Assert.AreEqual(640, collection[0].Page.Width);
        Assert.AreEqual(640, collection[0].Page.Height);
        Assert.AreEqual(0, collection[0].Page.X);
        Assert.AreEqual(0, collection[0].Page.Y);

        Assert.AreEqual(640, collection[1].Page.Width);
        Assert.AreEqual(640, collection[1].Page.Height);
        Assert.AreEqual(0, collection[0].Page.X);
        Assert.AreEqual(0, collection[0].Page.Y);
      }
    }
    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);
      }
    }
    public void Test_OptimizeTransparency()
    {
      using (MagickImageCollection collection = new MagickImageCollection())
      {
        ExceptionAssert.Throws<InvalidOperationException>(delegate ()
        {
          collection.OptimizeTransparency();
        });

        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.OptimizeTransparency();

        Assert.AreEqual(11, collection[1].Width);
        Assert.AreEqual(11, collection[1].Height);
        Assert.AreEqual(0, collection[1].Page.X);
        Assert.AreEqual(0, collection[1].Page.Y);
        ColorAssert.AreEqual(MagickColors.Lime, collection[1], 5, 5);
        ColorAssert.AreEqual(new MagickColor("#f000"), collection[1], 4, 4);
      }
    }
Ejemplo n.º 17
0
		/**
		 * 指定されたディレクトリ内にある画像からGIFアニメーションを生成する
		 * @param {String} コマ画像が入っているディレクトリのパス
		 * @return {Boolean} 成功した場合はtrue
		 */
		Boolean GenerateAnimationGIF(String tmpDir, String dstPath) {
			String[] files = Directory.GetFiles(tmpDir);
			if (files.Length == 0) return false;
			using (MagickImageCollection collection = new MagickImageCollection()) {
				MagickImage canvas = new MagickImage(files[files.Length - 1]);
				canvas.AnimationDelay = 250;
				canvas.Scale((int)(canvas.Width * 0.5), (int)(canvas.Height * 0.5));
				collection.Add(canvas);

				int perFrame = (int)Math.Ceiling(600.0 / files.Length);
				foreach (String file in files) {
					canvas = new MagickImage(file);
					canvas.AnimationDelay = perFrame;
					canvas.Scale((int)(canvas.Width * 0.5), (int)(canvas.Height * 0.5));
					collection.Add(canvas);
				}

				collection.Optimize();
				collection.Write(dstPath);
			};
			return true;
		}
    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]);
        }
      }
    }
Ejemplo n.º 19
0
    private MagickImage Execute(XmlElement element, MagickImageCollection collection)
    {
      if (element.Name == "read")
      {
        collection.Add(CreateMagickImage(element));
        return null;
      }

      if (element.Name == "write")
      {
        string fileName_ = XmlHelper.GetAttribute<string>(element, "fileName");
        collection.Write(fileName_);
        return null;
      }

      return ExecuteCollection(element, collection);
    }
    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);
        }
      }
    }
    public void Test_Evaluate()
    {
      using (MagickImageCollection collection = new MagickImageCollection())
      {
        ExceptionAssert.Throws<InvalidOperationException>(delegate ()
        {
          collection.Evaluate(EvaluateOperator.Exponential);
        });

        collection.Add(new MagickImage(MagickColors.Yellow, 40, 10));

        using (MagickImageCollection frames = new MagickImageCollection())
        {
          frames.Add(new MagickImage(MagickColors.Green, 10, 10));
          frames.Add(new MagickImage(MagickColors.White, 10, 10));
          frames.Add(new MagickImage(MagickColors.Black, 10, 10));
          frames.Add(new MagickImage(MagickColors.Yellow, 10, 10));

          collection.Add(frames.AppendHorizontally());
        }

        using (MagickImage image = collection.Evaluate(EvaluateOperator.Min))
        {
          ColorAssert.AreEqual(MagickColors.Green, image, 0, 0);
          ColorAssert.AreEqual(MagickColors.Yellow, image, 10, 0);
          ColorAssert.AreEqual(MagickColors.Black, image, 20, 0);
          ColorAssert.AreEqual(MagickColors.Yellow, image, 30, 0);
        }
      }
    }
    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);
        }
      }
    }
Ejemplo n.º 23
0
    public void Test_SubImageSearch()
    {
      using (MagickImageCollection images = new MagickImageCollection())
      {
        images.Add(new MagickImage(Color.Green, 2, 2));
        images.Add(new MagickImage(Color.Red, 2, 2));

        using (MagickImage combined = images.AppendHorizontally())
        {
          using (MagickSearchResult searchResult = combined.SubImageSearch(new MagickImage(Color.Red, 0, 0), ErrorMetric.RootMeanSquared))
          {
            Assert.IsNotNull(searchResult);
            Assert.IsNotNull(searchResult.SimilarityImage);
            Assert.IsNotNull(searchResult.BestMatch);
            Assert.AreEqual(0.0, searchResult.SimilarityMetric);
            Assert.AreEqual(2, searchResult.BestMatch.X);
            Assert.AreEqual(0, searchResult.BestMatch.Y);
          }
        }
      }
    }
    public void Test_Deconstruct()
    {
      using (MagickImageCollection collection = new MagickImageCollection())
      {
        ExceptionAssert.Throws<InvalidOperationException>(delegate ()
        {
          collection.Deconstruct();
        });

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

        using (MagickImageCollection frames = new MagickImageCollection())
        {
          frames.Add(new MagickImage(MagickColors.Red, 10, 20));
          frames.Add(new MagickImage(MagickColors.Purple, 10, 20));

          collection.Add(frames.AppendHorizontally());
        }

        Assert.AreEqual(20, collection[1].Width);
        Assert.AreEqual(20, collection[1].Height);
        Assert.AreEqual(new MagickGeometry(0, 0, 20, 20), collection[1].Page);
        ColorAssert.AreEqual(MagickColors.Red, collection[1], 3, 3);

        collection.Deconstruct();

        Assert.AreEqual(10, collection[1].Width);
        Assert.AreEqual(20, collection[1].Height);
        Assert.AreEqual(new MagickGeometry(10, 0, 20, 20), collection[1].Page);
        ColorAssert.AreEqual(MagickColors.Purple, collection[1], 3, 3);
      }
    }
    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);
        });
      }
    }
        private void MakeMosaic(List<string> list)
        {
            using (MagickImageCollection images = new MagickImageCollection())
            {
                foreach (string imagePath in lstFilesFound)
                {
                    try
                    {
                        MagickImage first = new MagickImage(imagePath);
                        images.Add(first);
                    }
                    catch (Exception ex)
                    {
                        if (ex is MagickCorruptImageErrorException || ex is MagickImageErrorException ||
                            ex is MagickDelegateErrorException || ex is MagickMissingDelegateErrorException ||
                            ex is MagickFileOpenErrorException)
                        {
                            //Not an image, or improper image
                            Console.WriteLine(ex.Message);
                        }
                    }

                }

                MediaInfo info = new MediaInfo(lstFilesFound);
                Options options = new Options();
                options.DropShadow = false;
                options.AutoFitTiles = true;
                options.Details = true;
                options.TileHeight = 180;
                options.TileWidth = 240;
                //options.DetailText = Path.GetDirectoryName(lstFilesFound[0]);

                //MagickImageCollection imagesbmp = new MagickImageCollection();
                //foreach (MagickImage magickImage in images)
                //{
                //    imagesbmp.Add(magickImage.ToBitmap());
                //}
                Thumbnailer thumbnailer = new Thumbnailer(info, options, images);

                // path is your file path
                //string directory = Path.GetDirectoryName(info.DirectoryPath);
                string directoryString = CreateDirectoryString(new DirectoryInfo(info.DirectoryPath));

                string path = Path.Combine(info.DirectoryPath, "contact-sheet");
                thumbnailer.Result.Save(path, ImageFormat.Jpeg);
            }
        }
    public void Test_Morph()
    {
      using (MagickImageCollection 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);
      }
    }
Ejemplo n.º 28
0
        private void saveAsGifToolStripMenuItem_Click(object sender, EventArgs e)
        {
            String savedgif = null;
            saveFileDialog1.FileName = "animation.gif";
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {

                savedgif = saveFileDialog1.FileName;

                String[] images = new String[arrayOfImages.Length];
                String log = "";
                int i = 0;
                String tmpDir = @"tmp\";
                if(Directory.Exists(@"tmp\")){

                } else {
                    Directory.CreateDirectory(@"tmp\");
                }
                using (ImageMagick.MagickImageCollection collection = new MagickImageCollection())
                {

                    foreach (PictureBox image in arrayOfImages)
                    {
                        Bitmap temp = (Bitmap)image.Image;
                        String name = tmpDir +"img" + i + ".png";
                       temp.Save(name);
                        images[i] = name;
                        i += 1;
                    }

                    foreach (String s in images)
                    {
                       collection.Add(s);
                       collection.Write(savedgif);
                        log += s;
                    }

                   // MessageBox.Show(log);

                    ImageWindow pos = new ImageWindow(wind, savedgif);
                }
            }
        }
    public void Test_Mosaic()
    {
      using (MagickImageCollection collection = new MagickImageCollection())
      {
        ExceptionAssert.Throws<InvalidOperationException>(delegate ()
        {
          collection.Mosaic();
        });

        collection.Add(Files.SnakewarePNG);
        collection.Add(Files.ImageMagickJPG);

        using (MagickImage mosaic = collection.Mosaic())
        {
          Assert.AreEqual(286, mosaic.Width);
          Assert.AreEqual(118, mosaic.Height);
        }
      }
    }
Ejemplo n.º 30
0
        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);

            }
            
        }
Ejemplo n.º 31
-1
        /// <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}");
                    }
                   
                }
        
            }
        }