private void RotateColors(Bitmap image, float degrees)
{
ImageAttributes imageAttributes = new ImageAttributes();
int width = image.Width;
int height = image.Height;
double r = degrees * System.Math.PI / 180; // degrees to radians
float cosR = (float)Math.Cos(r);
float sinR = (float)Math.Sin(r);
float a = (1 + 2 * cosR) / 3;
float b = ((1 - cosR) - (float)Math.Sqrt(3) * sinR) / 3;
float c = ((1 - cosR) + (float)Math.Sqrt(3) * sinR) / 3;
float[][] colorMatrixElements = {
new float[] {a, b, c, 0, 0},
new float[] {c, a, b, 0, 0},
new float[] {b, c, a, 0, 0},
new float[] {0, 0, 0, 1, 0},
new float[] {0, 0, 0, 0, 1}};
ColorMatrix colorMatrix = new ColorMatrix(colorMatrixElements);
imageAttributes.SetColorMatrix(
colorMatrix,
ColorMatrixFlag.Default,
ColorAdjustType.Bitmap);
using (Graphics g = Graphics.FromImage(image))
{
g.DrawImage(
image,
new Rectangle(0, 0, width, height), // destination rectangle
0, 0, // upper-left corner of source rectangle
width, // width of source rectangle
height, // height of source rectangle
GraphicsUnit.Pixel,
imageAttributes);
}
}
CSharp color
<iframe width="100%" height="866" src="http://snip.yosko.net/index.php?embed=5200a7a453a92" type="text/html"></iframe>
Text only - Permalink - Snippet public post date 06/08/2013