.net 设置图片透明度

  /// 
  /// 设置图片透明度
  /// 
  /// 
  /// 
  /// 
  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;

你可能感兴趣的:(c#)