Пример #1
0
    public void Test_Clip()
    {
      using (MagickImage image = new MagickImage(Files.InvitationTif))
      {
        image.Clip("Pad A", false);
        Assert.IsNotNull(image.Mask);

        using (PixelCollection pixels = image.Mask.GetReadOnlyPixels())
        {
          Pixel pixelA = pixels.GetPixel(0, 0);
          Pixel pixelB = pixels.GetPixel(pixels.Width - 1, pixels.Height - 1);
          for (int i = 0; i < 3; i++)
          {
            Assert.AreEqual(0, pixelA.GetChannel(i));
            Assert.AreEqual(0, pixelB.GetChannel(i));
          }
        }
      }
    }
Пример #2
0
 private void ExecuteClip(XmlElement element, MagickImage image)
 {
   Hashtable arguments = new Hashtable();
   foreach (XmlAttribute attribute in element.Attributes)
   {
     if (attribute.Name == "inside")
       arguments["inside"] = Variables.GetValue<Boolean>(attribute);
     else if (attribute.Name == "pathName")
       arguments["pathName"] = Variables.GetValue<String>(attribute);
   }
   if (arguments.Count == 0)
     image.Clip();
   else if (OnlyContains(arguments, "pathName", "inside"))
     image.Clip((String)arguments["pathName"], (Boolean)arguments["inside"]);
   else
     throw new ArgumentException("Invalid argument combination for 'clip', allowed combinations are: [] [pathName, inside]");
 }
Пример #3
-1
    private static void Test_Clip(bool inside, QuantumType value)
    {
      using (MagickImage image = new MagickImage(Files.InvitationTif))
      {
        image.Alpha(AlphaOption.Transparent);
        image.Clip("Pad A", inside);
        image.Alpha(AlphaOption.Opaque);

        using (MagickImage mask = image.WriteMask)
        {
          Assert.IsNotNull(mask);
          Assert.AreEqual(false, mask.HasAlpha);

          using (PixelCollection pixels = mask.GetPixels())
          {
            MagickColor pixelA = pixels.GetPixel(0, 0).ToColor();
            MagickColor pixelB = pixels.GetPixel(mask.Width - 1, mask.Height - 1).ToColor();

            Assert.AreEqual(pixelA, pixelB);
            Assert.AreEqual(value, pixelA.R);
            Assert.AreEqual(value, pixelA.G);
            Assert.AreEqual(value, pixelA.B);

            MagickColor pixelC = pixels.GetPixel(mask.Width / 2, mask.Height / 2).ToColor();
            Assert.AreEqual(Quantum.Max - value, pixelC.R);
            Assert.AreEqual(Quantum.Max - value, pixelC.G);
            Assert.AreEqual(Quantum.Max - value, pixelC.B);
          }
        }
      }
    }