1: /// <summary>
2: /// Gets the Green filter for an image
3: /// </summary>
4: /// <param name="Image">Image to change</param>
5: /// <returns>A bitmap object</returns>
6: public static Bitmap GreenFilter(Bitmap Image)
7: {
8: ColorMatrix TempMatrix = new ColorMatrix();
9: TempMatrix.Matrix = new float[][]{
10: new float[] {0, 0, 0, 0, 0},
11: new float[] {0, 1, 0, 0, 0},
12: new float[] {0, 0, 0, 0, 0},
13: new float[] {0, 0, 0, 1, 0},
14: new float[] {0, 0, 0, 0, 1}
15: };
16: return TempMatrix.Apply(Image);
17: }
18:
19: /*
20: Copyright (c) 2010 <a href="http://www.gutgames.com">James Craig</a>
21:
22: Permission is hereby granted, free of charge, to any person obtaining a copy
23: of this software and associated documentation files (the "Software"), to deal
24: in the Software without restriction, including without limitation the rights
25: to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
26: copies of the Software, and to permit persons to whom the Software is
27: furnished to do so, subject to the following conditions:
28:
29: The above copyright notice and this permission notice shall be included in
30: all copies or substantial portions of the Software.
31:
32: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33: IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34: FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35: AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36: LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37: OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
38: THE SOFTWARE.*/
39:
40: #region Usings
41: using System.Drawing;
42: using System.Drawing.Imaging;
43: #endregion
44:
45: namespace Utilities.Media.Image
46: {
47: /// <summary>
48: /// Helper class for setting up and applying a color matrix
49: /// </summary>
50: public class ColorMatrix
51: {
52: #region Constructor
53:
54: /// <summary>
55: /// Constructor
56: /// </summary>
57: public ColorMatrix()
58: {
59: }
60:
61: #endregion
62:
63: #region Properties
64:
65: /// <summary>
66: /// Matrix containing the values of the ColorMatrix
67: /// </summary>
68: public float[][] Matrix { get; set; }
69:
70: #endregion
71:
72: #region Public Functions
73:
74: /// <summary>
75: /// Applies the color matrix
76: /// </summary>
77: /// <param name="OriginalImage">Image sent in</param>
78: /// <returns>An image with the color matrix applied</returns>
79: public Bitmap Apply(Bitmap OriginalImage)
80: {
81: Bitmap NewBitmap = new Bitmap(OriginalImage.Width, OriginalImage.Height);
82: using (Graphics NewGraphics = Graphics.FromImage(NewBitmap))
83: {
84: System.Drawing.Imaging.ColorMatrix NewColorMatrix = new System.Drawing.Imaging.ColorMatrix(Matrix);
85: using (ImageAttributes Attributes = new ImageAttributes())
86: {
87: Attributes.SetColorMatrix(NewColorMatrix);
88: NewGraphics.DrawImage(OriginalImage,
89: new System.Drawing.Rectangle(0, 0, OriginalImage.Width, OriginalImage.Height),
90: 0, 0, OriginalImage.Width, OriginalImage.Height,
91: GraphicsUnit.Pixel,
92: Attributes);
93: }
94: }
95: return NewBitmap;
96: }
97:
98: #endregion
99: }
100: }