/// <summary> /// Processes the image. /// </summary> /// <param name="factory"> /// The the current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class containing /// the image to process. /// </param> /// <param name="image">The current image to process</param> /// <param name="newImage">The new Image to return</param> /// <returns> /// The processed image from the current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class. /// </returns> public Image TransformImage(ImageFactory factory, Image image, Image newImage) { using (Graphics graphics = Graphics.FromImage(newImage)) { using (ImageAttributes attributes = new ImageAttributes()) { attributes.SetColorMatrix(this.Matrix); Rectangle rectangle = new Rectangle(0, 0, image.Width, image.Height); graphics.DrawImage(image, rectangle, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes); // Overlay the image with some semi-transparent colors to finish the effect. using (GraphicsPath path = new GraphicsPath()) { path.AddRectangle(rectangle); // Paint a burgundy rectangle with a transparency of ~30% over the image. // Paint a blue rectangle with a transparency of 20% over the image. using (SolidBrush brush = new SolidBrush(Color.FromArgb(77, 38, 14, 28))) { Region oldClip = graphics.Clip; graphics.Clip = new Region(rectangle); graphics.FillRectangle(brush, rectangle); // Fill the blue. brush.Color = Color.FromArgb(51, 29, 32, 59); graphics.FillRectangle(brush, rectangle); graphics.Clip = oldClip; } } } } // Add brightness and contrast to finish the effect. factory.Update(newImage); Brightness brightness = new Brightness { DynamicParameter = 5 }; newImage = (Bitmap)brightness.ProcessImage(factory); factory.Update(newImage); Contrast contrast = new Contrast { DynamicParameter = 85 }; newImage = (Bitmap)contrast.ProcessImage(factory); // Reassign the image. image.Dispose(); image = newImage; return(image); }
/// <summary> /// Changes the brightness of the current image. /// </summary> /// <param name="percentage"> /// The percentage by which to alter the images brightness. /// Any integer between -100 and 100. /// </param> /// <returns> /// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class. /// </returns> public ImageFactory Brightness(int percentage) { if (this.ShouldProcess) { // Sanitize the input. if (percentage > 100 || percentage < -100) { percentage = 0; } Brightness brightness = new Brightness { DynamicParameter = percentage }; this.Image = brightness.ProcessImage(this); } return(this); }