protected override void Execute(CodeActivityContext context) { Image originalImage = context.GetValue(this.ImageToConvert); Color undesiredColor = context.GetValue(this.ColorToChange); Color desiredColor = context.GetValue(this.ColorToSet); // Get number of pixels to skip int skipLeft = context.GetValue(this.SkipPixelsFromLeft); int skipTop = context.GetValue(this.SkipPixelsFromTop); int skipRight = context.GetValue(this.SkipPixelsFromRight); int skipBottom = context.GetValue(this.SkipPixelsFromBottom); Bitmap newBitmap = new Bitmap(originalImage); for (int x = 0 + skipLeft; x < newBitmap.Width - skipRight; x++) { for (int y = 0 + skipBottom; y < newBitmap.Height - skipTop; y++) { var originalColor = newBitmap.GetPixel(x, y); if (StaticHelpers.ClassifyAsGeneralColor(originalColor) == undesiredColor) { newBitmap.SetPixel(x, y, desiredColor); } } } ChangedImage.Set(context, newBitmap); }
protected override void Execute(CodeActivityContext context) { Bitmap originalImage = (Bitmap)context.GetValue(this.ImageToCheck); // Get number of pixels to skip int skipLeft = context.GetValue(this.SkipPixelsFromLeft); int skipTop = context.GetValue(this.SkipPixelsFromTop); int skipRight = context.GetValue(this.SkipPixelsFromRight); int skipBottom = context.GetValue(this.SkipPixelsFromBottom); var foundColors = new Dictionary <Color, double>(); long totalScannedPixels = 0; for (int x = 0 + skipLeft; x < originalImage.Width - skipRight; x++) { for (int y = 0 + skipBottom; y < originalImage.Height - skipTop; y++) { var originalColor = StaticHelpers.ClassifyAsGeneralColor(originalImage.GetPixel(x, y)); if (foundColors.ContainsKey(originalColor)) { foundColors[originalColor] += 1; } else { foundColors[originalColor] = 1; } totalScannedPixels += 1; } } var sortedFoundColors = new SortedList <double, Color>(foundColors.Count()); foreach (var color in foundColors.Keys) { sortedFoundColors.Add(foundColors[color] / totalScannedPixels, color); } ColorsInImage.Set(context, sortedFoundColors); }