JD2022-TU1/main/tools/framework/JD.Winforms/Drawing/ImageUtility.cs

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);
}
}
}