winfrom 改变图片透明度 Alpha

效果图:

winfrom 改变图片透明度 Alpha

核心代码:

      /// <summary>
/// 方法一 设置图像透明度
/// </summary>
/// <param name="srcImage"></param>
/// <param name="opacity"></param>
/// <returns></returns>
public static Image TransparentImage(Image srcImage, float opacity)
{
float[][] nArray ={ 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, opacity, 0},
new float[] {0, 0, 0, 0, 1}};
ColorMatrix matrix = new ColorMatrix(nArray);
ImageAttributes attributes = new ImageAttributes();
attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
Bitmap resultImage = new Bitmap(srcImage.Width, srcImage.Height);
Graphics g = Graphics.FromImage(resultImage);
g.DrawImage(srcImage, new Rectangle(0, 0, srcImage.Width, srcImage.Height), 0, 0, srcImage.Width, srcImage.Height, GraphicsUnit.Pixel, attributes); return resultImage;
}

  

Demo下载 https://download.csdn.net/download/u011392711/11144010

上一篇:用Python编写博客导出工具


下一篇:[其它]iOS 12.2支持电信VoLTE了,中国电信教你如何开通:只要三步