码迷,mamicode.com
首页 > 其他好文 > 详细

处理图片透明操作

时间:2015-11-13 14:36:49      阅读:247      评论:0      收藏:0      [点我收藏+]

标签:

// <summary>  
/// 处理图片透明操作  
/// </summary>  
/// <param name="srcImage">原始图片</param>  
/// <param name="opacity">透明度(0.0---1.0)</param>  
/// <returns></returns>  
private 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;  
}  

  

处理图片透明操作

标签:

原文地址:http://www.cnblogs.com/CJSTONE/p/4961835.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!