Advertisement
THE_LORD

Draw Image With Custom Color

Mar 10th, 2017
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 KB | None | 0 0
  1.         /// <summary>
  2.         /// <param name="G"> The Graphic to draw the image </param>
  3.         /// <param name="R"> The Rectangle area of image </param>
  4.         /// <param name="_Image"> The image that the custom color applies on it</param>
  5.         /// <param name="C">The Color that be applied to the image </param>
  6.         /// <remarks></remarks>
  7.         /// </summary>
  8.         public void DrawImageWithColor(Graphics G, Rectangle R, Image _Image, Color C)
  9.         {
  10.             float[][] ptsArray = new float[][]
  11.         {
  12.             new float[] { Convert.ToSingle((double)C.R / 255.0), 0f, 0f, 0f, 0f },
  13.             new float[] { 0f, Convert.ToSingle((double)C.G / 255.0), 0f, 0f, 0f },
  14.             new float[] { 0f, 0f, Convert.ToSingle((double)C.B / 255.0), 0f, 0f },
  15.             new float[] { 0f, 0f, 0f, Convert.ToSingle((double)C.A / 255.0), 0f },
  16.             new float[] { Convert.ToSingle((double)C.R / 255.0),
  17.                 Convert.ToSingle((double)C.G / 255.0),
  18.                 Convert.ToSingle((double)C.B / 255.0), 0f,
  19.                 Convert.ToSingle((double)C.A / 255.0) }
  20.         };
  21.             System.Drawing.Imaging.ImageAttributes imgAttribs = new System.Drawing.Imaging.ImageAttributes();
  22.             imgAttribs.SetColorMatrix(new System.Drawing.Imaging.ColorMatrix(ptsArray), System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Default);
  23.             G.DrawImage(_Image, R, 0, 0, _Image.Width, _Image.Height, GraphicsUnit.Pixel, imgAttribs);
  24.             _Image.Dispose();
  25.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement