Added mask color matrix

This commit is contained in:
Jaex 2021-08-18 21:30:21 +03:00
parent 1db69d0e66
commit e424830c56
2 changed files with 13 additions and 11 deletions

View file

@ -234,5 +234,17 @@ public static ColorMatrix Colorize(Color color, float value)
new float[] { 0, 0, 0, 0, 1 }
});
}
public static ColorMatrix Mask(float opacity, Color color)
{
return new ColorMatrix(new[]
{
new float[] { 0, 0, 0, 0, 0 },
new float[] { 0, 0, 0, 0, 0 },
new float[] { 0, 0, 0, 0, 0 },
new float[] { 0, 0, 0, opacity, 0 },
new float[] { ((float)color.R).Remap(0, 255, 0, 1), ((float)color.G).Remap(0, 255, 0, 1), ((float)color.B).Remap(0, 255, 0, 1), 0, 1 }
});
}
}
}

View file

@ -1002,18 +1002,8 @@ public static Bitmap AddShadow(Bitmap bmp, float opacity, int size, float darkne
try
{
shadowImage = bmp.CreateEmptyBitmap(size * 2, size * 2);
ColorMatrix maskMatrix = new ColorMatrix();
maskMatrix.Matrix00 = 0;
maskMatrix.Matrix11 = 0;
maskMatrix.Matrix22 = 0;
maskMatrix.Matrix33 = opacity;
maskMatrix.Matrix40 = ((float)color.R).Remap(0, 255, 0, 1);
maskMatrix.Matrix41 = ((float)color.G).Remap(0, 255, 0, 1);
maskMatrix.Matrix42 = ((float)color.B).Remap(0, 255, 0, 1);
Rectangle shadowRectangle = new Rectangle(size, size, bmp.Width, bmp.Height);
maskMatrix.Apply(bmp, shadowImage, shadowRectangle);
ColorMatrixManager.Mask(opacity, color).Apply(bmp, shadowImage, shadowRectangle);
if (size > 0)
{