本文整理汇总了C#中ImageMagick.MagickImage.CopyPixels方法的典型用法代码示例。如果您正苦于以下问题:C# MagickImage.CopyPixels方法的具体用法?C# MagickImage.CopyPixels怎么用?C# MagickImage.CopyPixels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageMagick.MagickImage
的用法示例。
在下文中一共展示了MagickImage.CopyPixels方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteCopyPixels
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]");
}
示例2: Test_CopyPixels
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);
}
}
}
示例3: ExecuteCopyPixels
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_);
}
示例4: Test_CopyPixels
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);
}
}
}