17 lines
621 B
C#
17 lines
621 B
C#
using System.Drawing;
|
|
using System.Drawing.Imaging;
|
|
|
|
namespace JD.Winforms.Drawing
|
|
{
|
|
public static class ImageUtility
|
|
{
|
|
public static void DrawImageWithOpacity(this Graphics graphics, Bitmap image, Rectangle bounds, float opacity)
|
|
{
|
|
var matrix = new ColorMatrix();
|
|
matrix.Matrix33 = opacity;
|
|
var attributes = new ImageAttributes();
|
|
attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
|
|
graphics.DrawImage(image, bounds, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes);
|
|
}
|
|
}
|
|
}
|