コード例 #1
1
ファイル: MainWindow.cs プロジェクト: kaetemi/GifCapture
 private void SaveFile()
 {
     try
     {
         progress = 0;
         progressMax = (recorded.Count * 4);
         MagickImage[] mia = new MagickImage[recorded.Count];
         Parallel.For(0, recorded.Count, (i) =>
         {
             mia[i] = new MagickImage(recorded[i].Bitmap);
             int pr = Interlocked.Increment(ref progress);
             if (pr % 16 == 0) Invoke(new EmptyCallback(showProgress));
         });
         progressMax = progress + (mia.Length * 3);
         bool[] mid = new bool[mia.Length];
         mid[0] = false;
         Parallel.For(1, mia.Length, (i) =>
         {
             mid[i] = mia[i].Equals(mia[i - 1]);
             int pr = Interlocked.Increment(ref progress);
             if (pr % 4 == 0) Invoke(new EmptyCallback(showProgress));
         });
         Parallel.For(1, mia.Length, (i) =>
         {
             if (mid[i])
             {
                 mia[i].Dispose();
                 mia[i] = null;
             }
         });
         progressMax = progress + (mia.Length * 2);
         MagickImageCollection mic = new MagickImageCollection();
         QuantizeSettings qs = new QuantizeSettings();
         qs.Colors = 256;
         int timeOffset = 0;
         int addi = -1;
         for (int i = 0; i < mia.Length; ++i)
         {
             MagickImage mi = mia[i];
             int addDelay;
             if (mi != null)
             {
                 mic.Add(mi);
                 ++addi;
                 addDelay = 0;
             }
             else
             {
                 addDelay = mic[addi].AnimationDelay;
             }
             int delayMs = recorded[((i + 1) < recorded.Count) ? i + 1 : i].Time + timeOffset;
             int delayCs = delayMs / 10;
             timeOffset = delayMs - (delayCs * 10);
             mic[addi].AnimationDelay = delayCs + addDelay;
             ++progress;
             if (progress % 32 == 0) Invoke(new EmptyCallback(showProgress));
         }
         // mic.OptimizePlus();
         progressMax = progress + (mic.Count);
         Parallel.For(0, mic.Count, (i) =>
         {
             mic[i].Quantize(qs);
             int pr = Interlocked.Increment(ref progress);
             Invoke(new EmptyCallback(showProgress));
         });
         mic.Write(fileName);
         Parallel.For(0, mic.Count, (i) =>
         {
             mic[i].Dispose();
         });
         mic.Dispose();
         GC.Collect();
     }
     catch (Exception ex)
     {
         exc = ex;
     }
     Invoke(new EmptyCallback(doneSaving));
 }
コード例 #2
0
ファイル: PdfCov.cs プロジェクト: Centny/cswf.doc
 public override void Exec()
 {
     //var pages = this.Beg;
     L.D("executing pdf2img by file({0}),destination format({1})", this.AsSrc, this.AsDstF);
     this.Cdl.add();
     var tf_base = Path.GetTempFileName();
     var tf = tf_base + Path.GetExtension(this.AsSrc);
     MagickImageCollection images = new MagickImageCollection();
     try
     {
         File.Copy(this.AsSrc, tf, true);
         this.Pdf2imgProc(images, tf, -1, 0);
     }
     catch (Exception e)
     {
         L.E(e, "executing pdf2img by file({0}),destination format({1}) fail with error->{2}", tf, this.AsDstF, e.Message);
         this.Result.Code = 500;
         this.Fails.Add(e);
     }
     try
     {
         File.Delete(tf);
         File.Delete(tf_base);
     }
     catch (Exception e)
     {
         L.W("executing pdf2img on delete temp file({0}) error->{1}", tf, e.Message);
     }
     this.Cdl.done();
     this.Cdl.wait();
     images.Dispose();
     L.D("executing pdf2img by file({0}),destination format({1}) done with pages({2}),fails({3})", this.AsSrc, this.AsDstF, this.Result.Count, this.Fails.Count);
 }
コード例 #3
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);
      Test_Read(collection);

      collection.Read(new FileInfo(Files.RoseSparkleGIF));

      collection.Dispose();
    }
コード例 #4
0
    public void Test_Ping()
    {
      MagickImageCollection collection = new MagickImageCollection();

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

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

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

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

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

      collection.Ping(Files.FujiFilmFinePixS1ProJPG);
      Test_Ping(collection);
      Assert.AreEqual(600, collection[0].Width);
      Assert.AreEqual(400, collection[0].Height);

      collection.Ping(new FileInfo(Files.FujiFilmFinePixS1ProJPG));
      Test_Ping(collection);
      Assert.AreEqual(600, collection[0].Width);
      Assert.AreEqual(400, collection[0].Height);

      collection.Ping(File.ReadAllBytes(Files.FujiFilmFinePixS1ProJPG));
      Test_Ping(collection);
      Assert.AreEqual(600, collection[0].Width);
      Assert.AreEqual(400, collection[0].Height);

      collection.Read(Files.SnakewarePNG);
      Assert.AreEqual(286, collection[0].Width);
      Assert.AreEqual(67, collection[0].Height);
      using (PixelCollection pixels = collection[0].GetPixels())
      {
        Assert.AreEqual(38324, pixels.ToArray().Length);
      }

      collection.Dispose();
    }
コード例 #5
0
    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();
      });
    }