Beispiel #1
0
 private void ExecuteCopyPixels(XmlElement element, MagickImage image)
 {
   Hashtable arguments = new Hashtable();
   foreach (XmlAttribute attribute in element.Attributes)
   {
     if (attribute.Name == "channels")
       arguments["channels"] = Variables.GetValue<Channels>(attribute);
     else if (attribute.Name == "geometry")
       arguments["geometry"] = Variables.GetValue<MagickGeometry>(attribute);
     else if (attribute.Name == "offset")
       arguments["offset"] = Variables.GetValue<PointD>(attribute);
     else if (attribute.Name == "x")
       arguments["x"] = Variables.GetValue<Int32>(attribute);
     else if (attribute.Name == "y")
       arguments["y"] = Variables.GetValue<Int32>(attribute);
   }
   foreach (XmlElement elem in element.SelectNodes("*"))
   {
     arguments[elem.Name] = CreateMagickImage(elem);
   }
   if (OnlyContains(arguments, "source"))
     image.CopyPixels((MagickImage)arguments["source"]);
   else if (OnlyContains(arguments, "source", "channels"))
     image.CopyPixels((MagickImage)arguments["source"], (Channels)arguments["channels"]);
   else if (OnlyContains(arguments, "source", "geometry"))
     image.CopyPixels((MagickImage)arguments["source"], (MagickGeometry)arguments["geometry"]);
   else if (OnlyContains(arguments, "source", "geometry", "channels"))
     image.CopyPixels((MagickImage)arguments["source"], (MagickGeometry)arguments["geometry"], (Channels)arguments["channels"]);
   else if (OnlyContains(arguments, "source", "geometry", "offset"))
     image.CopyPixels((MagickImage)arguments["source"], (MagickGeometry)arguments["geometry"], (PointD)arguments["offset"]);
   else if (OnlyContains(arguments, "source", "geometry", "offset", "channels"))
     image.CopyPixels((MagickImage)arguments["source"], (MagickGeometry)arguments["geometry"], (PointD)arguments["offset"], (Channels)arguments["channels"]);
   else if (OnlyContains(arguments, "source", "geometry", "x", "y"))
     image.CopyPixels((MagickImage)arguments["source"], (MagickGeometry)arguments["geometry"], (Int32)arguments["x"], (Int32)arguments["y"]);
   else if (OnlyContains(arguments, "source", "geometry", "x", "y", "channels"))
     image.CopyPixels((MagickImage)arguments["source"], (MagickGeometry)arguments["geometry"], (Int32)arguments["x"], (Int32)arguments["y"], (Channels)arguments["channels"]);
   else
     throw new ArgumentException("Invalid argument combination for 'copyPixels', allowed combinations are: [source] [source, channels] [source, geometry] [source, geometry, channels] [source, geometry, offset] [source, geometry, offset, channels] [source, geometry, x, y] [source, geometry, x, y, channels]");
 }
    public void Test_CopyPixels()
    {
      using (MagickImage source = new MagickImage(Color.White, 100, 100))
      {
        using (MagickImage destination = new MagickImage(Color.Black, 50, 50))
        {
          ExceptionAssert.Throws<MagickOptionErrorException>(delegate ()
          {
            destination.CopyPixels(source, new MagickGeometry(51, 50), new Coordinate(0, 0));
          });

          ExceptionAssert.Throws<MagickOptionErrorException>(delegate ()
          {
            destination.CopyPixels(source, new MagickGeometry(50, 51), new Coordinate(0, 0));
          });

          ExceptionAssert.Throws<MagickOptionErrorException>(delegate ()
          {
            destination.CopyPixels(source, new MagickGeometry(50, 50), new Coordinate(1, 0));
          });

          ExceptionAssert.Throws<MagickOptionErrorException>(delegate ()
          {
            destination.CopyPixels(source, new MagickGeometry(50, 50), new Coordinate(0, 1));
          });

          destination.CopyPixels(source, new MagickGeometry(25, 25), new Coordinate(25, 25));

          Test_Pixel_Equal(destination, 0, 0, Color.Black);
          Test_Pixel_Equal(destination, 24, 24, Color.Black);
          Test_Pixel_Equal(destination, 25, 25, Color.White);
          Test_Pixel_Equal(destination, 49, 49, Color.White);
        }
      }
    }
Beispiel #3
0
 private void ExecuteCopyPixels(XmlElement element, MagickImage image)
 {
   MagickImage source_ = CreateMagickImage(element["source"]);
   MagickGeometry geometry_ = Variables.GetValue<MagickGeometry>(element, "geometry");
   Coordinate offset_ = CreateCoordinate(element["offset"]);
   image.CopyPixels(source_, geometry_, offset_);
 }
    public void Test_CopyPixels()
    {
      using (MagickImage source = new MagickImage(MagickColors.White, 100, 100))
      {
        using (MagickImage destination = new MagickImage(MagickColors.Black, 50, 50))
        {
          ExceptionAssert.Throws<ArgumentNullException>(delegate ()
          {
            destination.CopyPixels(null);
          });

          ExceptionAssert.Throws<ArgumentNullException>(delegate ()
          {
            destination.CopyPixels(null, Channels.Red);
          });

          ExceptionAssert.Throws<ArgumentNullException>(delegate ()
          {
            destination.CopyPixels(source, null);
          });

          ExceptionAssert.Throws<ArgumentNullException>(delegate ()
          {
            destination.CopyPixels(source, null, Channels.Green);
          });

          ExceptionAssert.Throws<ArgumentNullException>(delegate ()
          {
            destination.CopyPixels(source, null, 0, 0);
          });

          ExceptionAssert.Throws<ArgumentNullException>(delegate ()
          {
            destination.CopyPixels(source, null, 0, 0, Channels.Green);
          });

          ExceptionAssert.Throws<ArgumentNullException>(delegate ()
          {
            destination.CopyPixels(null, new MagickGeometry(10, 10));
          });

          ExceptionAssert.Throws<ArgumentNullException>(delegate ()
          {
            destination.CopyPixels(null, new MagickGeometry(10, 10), Channels.Black);
          });

          ExceptionAssert.Throws<ArgumentNullException>(delegate ()
          {
            destination.CopyPixels(null, new MagickGeometry(10, 10), 0, 0);
          });

          ExceptionAssert.Throws<ArgumentNullException>(delegate ()
          {
            destination.CopyPixels(null, new MagickGeometry(10, 10), 0, 0, Channels.Black);
          });

          ExceptionAssert.Throws<MagickOptionErrorException>(delegate ()
          {
            destination.CopyPixels(source, new MagickGeometry(51, 50), new PointD(0, 0));
          });

          ExceptionAssert.Throws<MagickOptionErrorException>(delegate ()
          {
            destination.CopyPixels(source, new MagickGeometry(50, 51), new PointD(0, 0));
          });

          ExceptionAssert.Throws<MagickOptionErrorException>(delegate ()
          {
            destination.CopyPixels(source, new MagickGeometry(50, 50), 1, 0);
          });

          ExceptionAssert.Throws<MagickOptionErrorException>(delegate ()
          {
            destination.CopyPixels(source, new MagickGeometry(50, 50), new PointD(0, 1));
          });

          destination.CopyPixels(source, new MagickGeometry(25, 25), 25, 25);

          ColorAssert.AreEqual(MagickColors.Black, destination, 0, 0);
          ColorAssert.AreEqual(MagickColors.Black, destination, 24, 24);
          ColorAssert.AreEqual(MagickColors.White, destination, 25, 25);
          ColorAssert.AreEqual(MagickColors.White, destination, 49, 49);

          destination.CopyPixels(source, new MagickGeometry(25, 25), 0, 25, Channels.Green);

          ColorAssert.AreEqual(MagickColors.Black, destination, 0, 0);
          ColorAssert.AreEqual(MagickColors.Black, destination, 24, 24);
          ColorAssert.AreEqual(MagickColors.White, destination, 25, 25);
          ColorAssert.AreEqual(MagickColors.White, destination, 49, 49);
          ColorAssert.AreEqual(MagickColors.Lime, destination, 0, 25);
          ColorAssert.AreEqual(MagickColors.Lime, destination, 24, 49);
        }
      }
    }