Created
May 4, 2014 12:33
-
-
Save ErikSchierboom/99cbec38a537d6e65c32 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace MonoColorMatrix | |
{ | |
using System.Drawing; | |
using System.Drawing.Imaging; | |
public class Program | |
{ | |
public static void Main() | |
{ | |
var brightnessFactor = -0.05f; | |
var image = Image.FromFile("input.jpg"); | |
var colorMatrix = new ColorMatrix( | |
new float[][] | |
{ | |
new float[] { 1, 0, 0, 0, 0 }, | |
new float[] { 0, 1, 0, 0, 0 }, | |
new float[] { 0, 0, 1, 0, 0 }, | |
new float[] { 0, 0, 0, 1, 0 }, | |
new float[] { brightnessFactor, brightnessFactor, brightnessFactor, 0, 1 } | |
}); | |
using (var graphics = Graphics.FromImage(image)) | |
{ | |
using (var imageAttributes = new ImageAttributes()) | |
{ | |
imageAttributes.SetColorMatrix(colorMatrix); | |
graphics.DrawImage(image, new Rectangle(0, 0, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imageAttributes); | |
} | |
} | |
// Saving the images results in incorrect images being output on Mono, for any chosen image format | |
image.Save("output.jpg", ImageFormat.Jpeg); | |
image.Save("output.png", ImageFormat.Png); | |
image.Save("output.bmp", ImageFormat.Bmp); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment