private MagickImage ExecuteMap(XmlElement element, MagickImageCollection collection) { Hashtable arguments = new Hashtable(); foreach (XmlElement elem in element.SelectNodes("*")) { if (elem.Name == "image") { arguments["image"] = CreateMagickImage(elem); } else if (elem.Name == "settings") { arguments["settings"] = CreateQuantizeSettings(elem); } } if (OnlyContains(arguments, "image")) { collection.Map((MagickImage)arguments["image"]); return(null); } else if (OnlyContains(arguments, "image", "settings")) { collection.Map((MagickImage)arguments["image"], (QuantizeSettings)arguments["settings"]); return(null); } else { throw new ArgumentException("Invalid argument combination for 'map', allowed combinations are: [image] [image, settings]"); } }
public void Test_Map() { using (MagickImageCollection colors = new MagickImageCollection()) { colors.Add(new MagickImage(MagickColors.Red, 1, 1)); colors.Add(new MagickImage(MagickColors.Green, 1, 1)); using (MagickImage remapImage = colors.AppendHorizontally()) { using (MagickImageCollection collection = new MagickImageCollection()) { ExceptionAssert.Throws<InvalidOperationException>(delegate () { collection.Map(null); }); ExceptionAssert.Throws<InvalidOperationException>(delegate () { collection.Map(remapImage); }); collection.Read(Files.RoseSparkleGIF); ExceptionAssert.Throws<ArgumentNullException>(delegate () { collection.Map(null); }); QuantizeSettings settings = new QuantizeSettings(); settings.DitherMethod = DitherMethod.FloydSteinberg; collection.Map(remapImage, settings); ColorAssert.AreEqual(MagickColors.Red, collection[0], 60, 17); ColorAssert.AreEqual(MagickColors.Green, collection[0], 37, 24); ColorAssert.AreEqual(MagickColors.Red, collection[1], 58, 30); ColorAssert.AreEqual(MagickColors.Green, collection[1], 36, 26); ColorAssert.AreEqual(MagickColors.Red, collection[2], 60, 40); ColorAssert.AreEqual(MagickColors.Green, collection[2], 17, 21); } } } }
private MagickImage ExecuteMap(XmlElement element, MagickImageCollection collection) { Hashtable arguments = new Hashtable(); foreach (XmlElement elem in element.SelectNodes("*")) { arguments[elem.Name] = CreateQuantizeSettings(elem); } if (arguments.Count == 0) { collection.Map(); return null; } else if (OnlyContains(arguments, "settings")) { collection.Map((QuantizeSettings)arguments["settings"]); return null; } else throw new ArgumentException("Invalid argument combination for 'map', allowed combinations are: [] [settings]"); }