/// <summary> /// Adjusts contrast using memory-friendly Pipeline API /// </summary> private static void BrightnessContrastMemoryFriendly() { using (var reader = ImageReader.Create("../../../../_Input/Chicago.jpg")) using (var brightnessContrast = new BrightnessContrast(0.1f, 0.2f)) using (var writer = ImageWriter.Create("../../../../_Output/BrightnessContrastMemoryFriendly.jpg")) { Pipeline.Run(reader + brightnessContrast + writer); } }
public IActionResult UpdateImage(int brightness, int contrast) //изменение яркости и контрастности { UInt32 p; image = new Bitmap(ActionPictureController.pathImage); // UInt32[,] pixel; //получение матрицы с пикселями pixel = new UInt32[image.Height, image.Width]; for (int y = 0; y < image.Height; y++) { for (int x = 0; x < image.Width; x++) { pixel[y, x] = (UInt32)(image.GetPixel(x, y).ToArgb()); } } //яркость for (int i = 0; i < image.Height; i++) { for (int j = 0; j < image.Width; j++) { p = BrightnessContrast.Brightness(pixel[i, j], brightness, 10); //получение значения цвета пискеля FromOnePixelToBitmap(i, j, p); //присвоение полученного цвета пикселю на картинке pixel[i, j] = (UInt32)(image.GetPixel(j, i).ToArgb()); //занесение нового цвета пикселя в матрицу, т. е. сохранение } } //контрастность for (int i = 0; i < image.Height; i++) { for (int j = 0; j < image.Width; j++) { p = BrightnessContrast.Contrast(pixel[i, j], contrast, 10); FromOnePixelToBitmap(i, j, p); pixel[i, j] = (UInt32)(image.GetPixel(j, i).ToArgb()); } } bitmapBytes = BitmapToBytes(image); image.Dispose(); string imreBase64Data = Convert.ToBase64String(bitmapBytes); string imgDataURL = string.Format("data:image/jpeg;base64,{0}", imreBase64Data); ViewBag.ImageData = imgDataURL; return(View("~/Views/Home/UpdateImage.cshtml")); }
/// <summary> /// Apply the current text settings to the values /// </summary> /// <param name="values">values array to be used</param> /// <returns>Array of strings from the values using the current settings</returns> public string[] Apply(byte[,] values) { if (values == null) { return(null); } // only apply brightness and contrast if necessary if (Brightness != 0 || Contrast != 0) { BrightnessContrast filter = new BrightnessContrast(IsBlackTextOnWhite ? Brightness : -Brightness, IsBlackTextOnWhite ? Contrast : -Contrast); values = filter.Apply(values); } if (Stretch) { Stretch filter = new Stretch(); values = filter.Apply(values); } if (Levels.Minimum != 0 || Levels.Maximum != 255 || Levels.Median != 0.5f) { //values = AscgenConverter.ApplyLevels(values, Levels.Minimum, Levels.Maximum, Levels.Median); Levels filter = new Levels(Levels.Minimum, Levels.Maximum, Levels.Median); values = filter.Apply(values); } if (Sharpen) { values = AsciiConverter.SharpenValues(values); } if (Unsharp) { values = AsciiConverter.UnsharpMaskValues(values, 3); } if (FlipHorizontally || FlipVertically) { Flip filter = new Flip(FlipHorizontally, FlipVertically); values = filter.Apply(values); } return(_ValuesToText.Apply(values)); }
private void Contrast_ValueChanger(object sender, RoutedPropertyChangedEventArgs <double> e) { ((Slider)sender).SelectionEnd = e.NewValue; BrightnessContrast.ChangeContrastForTick(contrastSlider); }