public string Execute(FileItem item, string infile, string dest, ValuePairEnumerator configData) { var conf = new ChromakeyViewModel(configData); dest = Path.Combine(Path.GetDirectoryName(dest), Path.GetFileNameWithoutExtension(dest) + ".jpg"); KalikoImage image = new KalikoImage(infile); var x = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(conf.BackgroundColor); var filter = new ChromaKeyFilter(); filter.KeyColor = Color.FromArgb(x.R, x.G, x.B); filter.ToleranceHue = conf.Hue; filter.ToleranceSaturnation = conf.Saturnation/100f; filter.ToleranceBrightness = conf.Brigthness / 100f; image.ApplyFilter(filter); var res = image.Clone(); if (conf.UnsharpMask) res.ApplyFilter(new UnsharpMaskFilter(1.4f, 1.32f, 5)); var backdrop = new KalikoImage(conf.BackgroundFile); backdrop = backdrop.Scale(new FitScaling(image.Width, image.Height)); backdrop.BlitImage(res); backdrop.SaveJpg(dest, 90); return dest; }
/// <summary>Crop the image into the given dimensions.</summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="width"></param> /// <param name="height"></param> public void Crop(int x, int y, int width, int height) { var image = new KalikoImage(width, height); image.BlitImage(Image, -x, -y); Image = image.Image; }