public void InvertColors() { storeTransformedBitmap(); cancellationTokenSource = new CancellationTokenSource(); int currentPerecentageCompleted = 0; int numberOfPixelsEdited = onePercentOfArea; for (int y = 0; y < TransformedBitmap.Height; y++) { for (int x = 0; x < TransformedBitmap.Width; x++) { if (cancellationTokenSource.Token.IsCancellationRequested) { undoImageChanges(); return; } Color newColor = getNewColorForInversionTransformation(TransformedBitmap.GetPixel(x, y)); TransformedBitmap.SetPixel(x, y, newColor); updateTransformationProgress(ref numberOfPixelsEdited, ref currentPerecentageCompleted); } } storeTransformedBitmap(); }
public void ChangeBrightness(int brightness) { // The minimum value for the brightness is BRIGHTNESS_MIN_VALUE and the maximum value is BRIGHTNESS_MAX_VALUE. Lower values represent darkening the photo, // and higher values represent brightening the photo. BRIGHTNESS_AVERAGE_VALUE represents no change. if (brightness < BRIGHTNESS_MIN_VALUE || brightness > BRIGHTNESS_MAX_VALUE) { throw new ArgumentException("The value for brightness cannot be greater than 100 or less than 0. Current value = " + brightness); } storeTransformedBitmap(); cancellationTokenSource = new CancellationTokenSource(); int currentPerecentageCompleted = 0; int numberOfPixelsEdited = onePercentOfArea; int amountToSubtractFromRgbValue = calculateAmountToSubtractFromRgbValue(brightness); for (int y = 0; y < TransformedBitmap.Height; y++) { for (int x = 0; x < TransformedBitmap.Width; x++) { if (cancellationTokenSource.Token.IsCancellationRequested) { undoImageChanges(); return; } Color newColor = getNewColorForBrightnessTransform(amountToSubtractFromRgbValue, TransformedBitmap.GetPixel(x, y)); TransformedBitmap.SetPixel(x, y, newColor); updateTransformationProgress(ref numberOfPixelsEdited, ref currentPerecentageCompleted); } } storeTransformedBitmap(); }
private double calculateAverageRgbValuesForPixel(int x, int y) { Color color = TransformedBitmap.GetPixel(x, y); return((color.R + color.G + color.B) / 3); }