public void Test_RemoveAlpha()
    {
      string tempFile = Path.GetTempPath() + Guid.NewGuid().ToString() + ".png";
      try
      {
        using (MagickImage image = new MagickImage(Files.MagickNETIconPNG))
        {
          Assert.IsTrue(image.HasAlpha);
          image.ColorAlpha(new MagickColor("yellow"));
          image.HasAlpha = true;
          image.Write(tempFile);

          image.Read(tempFile);

          // TODO: Figure out why this does not fail in a single run but does when all tests are run.
          //Assert.IsTrue(image.HasAlpha);

          PngOptimizer optimizer = new PngOptimizer();
          optimizer.LosslessCompress(tempFile);

          image.Read(tempFile);
          Assert.IsFalse(image.HasAlpha);
        }
      }
      finally
      {
        if (File.Exists(tempFile))
          File.Delete(tempFile);
      }
    }
    public void Test_RemoveAlpha()
    {
      string tempFile = GetTemporaryFileName(".png");

      try
      {
        using (MagickImage image = new MagickImage(Files.MagickNETIconPNG))
        {
          Assert.IsTrue(image.HasAlpha);
          image.ColorAlpha(new MagickColor("yellow"));
          image.HasAlpha = true;
          image.Write(tempFile);

          image.Read(tempFile);

          Assert.IsTrue(image.HasAlpha);

          PngOptimizer optimizer = new PngOptimizer();
          optimizer.LosslessCompress(tempFile);

          image.Read(tempFile);
          Assert.IsFalse(image.HasAlpha);
        }
      }
      finally
      {
        File.Delete(tempFile);
      }
    }
Beispiel #3
0
 private void ExecuteColorAlpha(XmlElement element, MagickImage image)
 {
   MagickColor color_ = Variables.GetValue<MagickColor>(element, "color");
   image.ColorAlpha(color_);
 }
    public void Test_IsOpaque()
    {
      using (MagickImage image = new MagickImage(Files.MagickNETIconPNG))
      {
        Assert.IsFalse(image.IsOpaque);
        image.ColorAlpha(Color.Purple);
        Assert.IsTrue(image.IsOpaque);
      }

      using (MagickImage image = new MagickImage(Files.Builtin.Logo))
      {
        Assert.IsTrue(image.IsOpaque);
        image.Opaque(Color.White, MagickColor.Transparent);
        Assert.IsFalse(image.IsOpaque);
      }
    }
    public void Test_ColorAlpha()
    {
      using (MagickImage image = new MagickImage(Files.MagickNETIconPNG))
      {
        MagickColor purple = new MagickColor("purple");

        image.ColorAlpha(purple);

        using (PixelCollection pixels = image.GetReadOnlyPixels())
        {
          ColorAssert.AreNotEqual(purple, pixels.GetPixel(45, 75).ToColor());
          ColorAssert.AreEqual(purple, pixels.GetPixel(100, 60).ToColor());
        }
      }
    }
    public void Test_ColorAlpha()
    {
      using (MagickImage image = new MagickImage(Files.MagickNETIconPNG))
      {
        MagickColor purple = new MagickColor("purple");

        image.ColorAlpha(purple);

        ColorAssert.AreNotEqual(purple, image, 45, 75);
        ColorAssert.AreEqual(purple, image, 100, 60);
      }
    }