本文整理汇总了C#中System.Drawing.Imaging.ColorMatrix.Apply方法的典型用法代码示例。如果您正苦于以下问题:C# ColorMatrix.Apply方法的具体用法?C# ColorMatrix.Apply怎么用?C# ColorMatrix.Apply使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Imaging.ColorMatrix
的用法示例。
在下文中一共展示了ColorMatrix.Apply方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddShadow
public static Bitmap AddShadow(Image sourceImage, float opacity, int size, float darkness, Color color, Point offset)
{
Image shadowImage = null;
try
{
shadowImage = sourceImage.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, sourceImage.Width, sourceImage.Height);
maskMatrix.Apply(sourceImage, shadowImage, shadowRectangle);
if (size > 0)
{
Blur((Bitmap)shadowImage, size);
}
if (darkness > 1)
{
ColorMatrix alphaMatrix = new ColorMatrix();
alphaMatrix.Matrix33 = darkness;
Image shadowImage2 = alphaMatrix.Apply(shadowImage);
shadowImage.Dispose();
shadowImage = shadowImage2;
}
Bitmap result = shadowImage.CreateEmptyBitmap(Math.Abs(offset.X), Math.Abs(offset.Y));
using (Graphics g = Graphics.FromImage(result))
{
g.SetHighQuality();
g.DrawImage(shadowImage, Math.Max(0, offset.X), Math.Max(0, offset.Y), shadowImage.Width, shadowImage.Height);
g.DrawImage(sourceImage, Math.Max(size, -offset.X + size), Math.Max(size, -offset.Y + size), sourceImage.Width, sourceImage.Height);
}
return result;
}
finally
{
if (sourceImage != null) sourceImage.Dispose();
if (shadowImage != null) shadowImage.Dispose();
}
}
示例2: Apply
public override Image Apply(Image img)
{
ColorMatrix colorMatrix = new ColorMatrix(new[]
{
new float[] { Rr, Gr, Br, Ar, 0 },
new float[] { Rg, Gg, Bg, Ag, 0 },
new float[] { Rb, Gb, Bb, Ab, 0 },
new float[] { Ra, Ga, Ba, Aa, 0 },
new float[] { Ro, Go, Bo, Ao, 1 }
});
using (img)
{
return colorMatrix.Apply(img);
}
}
示例3: Outline
public static Image Outline(Image img, int borderSize, Color borderColor)
{
Bitmap result = img.CreateEmptyBitmap(borderSize * 2, borderSize * 2);
ColorMatrix maskMatrix = new ColorMatrix();
maskMatrix.Matrix00 = 0;
maskMatrix.Matrix11 = 0;
maskMatrix.Matrix22 = 0;
maskMatrix.Matrix33 = 1;
maskMatrix.Matrix40 = ((float)borderColor.R).Remap(0, 255, 0, 1);
maskMatrix.Matrix41 = ((float)borderColor.G).Remap(0, 255, 0, 1);
maskMatrix.Matrix42 = ((float)borderColor.B).Remap(0, 255, 0, 1);
using (img)
using (Image shadow = maskMatrix.Apply(img))
using (Graphics g = Graphics.FromImage(result))
{
for (int i = 0; i <= borderSize * 2; i++)
{
g.DrawImage(shadow, new Rectangle(i, 0, shadow.Width, shadow.Height));
g.DrawImage(shadow, new Rectangle(i, borderSize * 2, shadow.Width, shadow.Height));
g.DrawImage(shadow, new Rectangle(0, i, shadow.Width, shadow.Height));
g.DrawImage(shadow, new Rectangle(borderSize * 2, i, shadow.Width, shadow.Height));
}
g.DrawImage(img, new Rectangle(borderSize, borderSize, img.Width, img.Height));
}
return result;
}
示例4: GreenFilter
/// <summary>
/// Gets the Green filter for an image
/// </summary>
/// <param name="Image">Image to change</param>
/// <param name="FileName">File to save to</param>
/// <returns>A bitmap object</returns>
public static Bitmap GreenFilter(this Bitmap Image, string FileName = "")
{
Image.ThrowIfNull("Image");
ImageFormat FormatUsing = FileName.GetImageFormat();
ColorMatrix TempMatrix = new ColorMatrix();
TempMatrix.Matrix = new float[][]{
new float[] {0, 0, 0, 0, 0},
new float[] {0, 1, 0, 0, 0},
new float[] {0, 0, 0, 0, 0},
new float[] {0, 0, 0, 1, 0},
new float[] {0, 0, 0, 0, 1}
};
Bitmap NewBitmap = TempMatrix.Apply(Image);
if (!string.IsNullOrEmpty(FileName))
NewBitmap.Save(FileName, FormatUsing);
return NewBitmap;
}
示例5: SepiaTone
/// <summary>
/// Converts an image to sepia tone
/// </summary>
/// <param name="Image">Image to change</param>
/// <param name="FileName">File to save to</param>
/// <returns>A bitmap object of the sepia tone image</returns>
public static Bitmap SepiaTone(this Bitmap Image, string FileName = "")
{
Image.ThrowIfNull("Image");
ImageFormat FormatUsing = FileName.GetImageFormat();
ColorMatrix TempMatrix = new ColorMatrix();
TempMatrix.Matrix = new float[][]{
new float[] {.393f, .349f, .272f, 0, 0},
new float[] {.769f, .686f, .534f, 0, 0},
new float[] {.189f, .168f, .131f, 0, 0},
new float[] {0, 0, 0, 1, 0},
new float[] {0, 0, 0, 0, 1}
};
Bitmap NewBitmap = TempMatrix.Apply(Image);
if (!string.IsNullOrEmpty(FileName))
NewBitmap.Save(FileName, FormatUsing);
return NewBitmap;
}
示例6: AdjustBrightness
/// <summary>
/// Adjusts the brightness
/// </summary>
/// <param name="Image">Image to change</param>
/// <param name="FileName">File to save to</param>
/// <param name="Value">-255 to 255</param>
/// <returns>A bitmap object</returns>
public static Bitmap AdjustBrightness(this Bitmap Image, int Value = 0, string FileName = "")
{
Image.ThrowIfNull("Image");
ImageFormat FormatUsing = FileName.GetImageFormat();
float FinalValue = (float)Value / 255.0f;
ColorMatrix TempMatrix = new ColorMatrix();
TempMatrix.Matrix = 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[] {FinalValue, FinalValue, FinalValue, 1, 1}
};
Bitmap NewBitmap = TempMatrix.Apply(Image);
if (!string.IsNullOrEmpty(FileName))
NewBitmap.Save(FileName, FormatUsing);
return NewBitmap;
}
示例7: GreenFilter
/// <summary>
/// Gets the Green filter for an image
/// </summary>
/// <param name="Image">Image to change</param>
/// <param name="FileName">File to save to</param>
/// <returns>A bitmap object</returns>
public static Bitmap GreenFilter(this Bitmap Image, string FileName = "")
{
Contract.Requires<ArgumentNullException>(Image != null, "Image");
ImageFormat FormatUsing = FileName.GetImageFormat();
ColorMatrix TempMatrix = new ColorMatrix();
TempMatrix.Matrix = new float[][]{
new float[] {0, 0, 0, 0, 0},
new float[] {0, 1, 0, 0, 0},
new float[] {0, 0, 0, 0, 0},
new float[] {0, 0, 0, 1, 0},
new float[] {0, 0, 0, 0, 1}
};
Bitmap NewBitmap = TempMatrix.Apply(Image);
if (!string.IsNullOrEmpty(FileName))
NewBitmap.Save(FileName, FormatUsing);
return NewBitmap;
}
示例8: BlueFilter
/// <summary>
/// Gets the blue filter for an image
/// </summary>
/// <param name="Image">Image to change</param>
/// <param name="FileName">File to save to</param>
/// <returns>A bitmap object</returns>
public static Bitmap BlueFilter(this Bitmap Image, string FileName = "")
{
if (Image == null)
throw new ArgumentNullException("Image");
ImageFormat FormatUsing = FileName.GetImageFormat();
ColorMatrix TempMatrix = new ColorMatrix();
TempMatrix.Matrix = new float[][]{
new float[] {0, 0, 0, 0, 0},
new float[] {0, 0, 0, 0, 0},
new float[] {0, 0, 1, 0, 0},
new float[] {0, 0, 0, 1, 0},
new float[] {0, 0, 0, 0, 1}
};
Bitmap NewBitmap = TempMatrix.Apply(Image);
if (!string.IsNullOrEmpty(FileName))
NewBitmap.Save(FileName, FormatUsing);
return NewBitmap;
}