candyzhmm

参照博文:http://blog.csdn.net/lexiaoyao20/article/details/6628830

最有效的一种方法:

矩阵法:

这个方法的效率最高。

 

    /// <summary>  
           /// 设置图片的透明度  
           /// </summary>  
           /// <param name="image">原图</param>  
           /// <param name="alpha">透明度0-255</param>  
           /// <returns></returns>  
           private Bitmap SetPictureAlpha(Image image,int alpha)  
           {  
               //颜色矩阵  
               float[][] matrixItems =  
               {  
                   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,alpha/255f,0},  
                   new float[]{0,0,0,0,1}  
               };  
               ColorMatrix colorMatrix = new ColorMatrix(matrixItems);  
               ImageAttributes imageAtt = new ImageAttributes();  
               imageAtt.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);  
               Bitmap bmp = new Bitmap(image.Width, image.Height);  
               Graphics g = Graphics.FromImage(bmp);  
               g.DrawImage(image, new Rectangle(0, 0, image.Width, image.Height),  
                       0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imageAtt);  
               g.Dispose();  
      
               return bmp;  
           }  

 

分类:

技术点:

相关文章:

  • 2021-08-13
  • 2021-12-23
  • 2021-10-11
  • 2021-11-14
  • 2021-12-16
  • 2021-09-29
  • 2021-11-17
  • 2021-10-01
猜你喜欢
  • 2021-11-30
  • 2021-10-20
  • 2021-11-20
  • 2021-10-20
  • 2021-12-25
  • 2021-09-04
  • 2021-10-30
相关资源
相似解决方案