GDI+ 如何实现像AlphaBlend函数样半透明效果?

解决方案 »

  1.   

    GDI+实现透明很简单,设置下啊落发值即可
      

  2.   

    看看MSDN上的:
    Using a Color Matrix to Set Alpha Values in Images
      

  3.   

    PNG 格式直接往上画就可以!
      

  4.   

    下面是一个淡入淡出的效果,你参考一下吧:Graphics g=this.CreateGraphics();
    g.Clear(Color.Black);
    Bitmap bitmap=new Bitmap("demo.bmp");
    int iWidth = bitmap.Width;
    int iHeight = bitmap.Height; //初始化色彩变换矩阵
    float[][] tem=
    {
    new float[]{0.0f, 0.0f, 0.0f, 0.0f, 0.0f},
    new float[]{0.0f, 0.0f, 0.0f, 0.0f, 0.0f},
    new float[]{0.0f, 0.0f, 0.0f, 0.0f, 0.0f},
    new float[]{0.0f, 0.0f, 0.0f, 1.0f, 0.0f},
    new float[]{0.0f, 0.0f, 0.0f, 0.0f, 1.0f}
    };

    ColorMatrix colorMatrix=new ColorMatrix(tem);
    ImageAttributes imageAtt=new ImageAttributes(); //从0到1进行修改色彩变换矩阵主对角线上的数值
    //使三种基准色的饱和度渐增
    for(float i=0.0f;i<=1.0f;i+=0.02f)
    {
    colorMatrix.Matrix00=i;
    colorMatrix.Matrix11=i;
    colorMatrix.Matrix22=i;
    colorMatrix.Matrix33=i;
    //设置色彩校正矩阵
    imageAtt.SetColorMatrix(colorMatrix,
    ColorMatrixFlag.Default,ColorAdjustType.Bitmap);
    //绘制图片
    g.DrawImage(
    bitmap, new Rectangle(0, 0, iWidth, iHeight), 
    0,0,        
    iWidth,iHeight,
    GraphicsUnit.Pixel, 
    imageAtt);
    } MessageBox.Show("下面演示淡出效果");

    //从1到0进行修改色彩变换矩阵主对角线上的数值
    //依次减少每种色彩分量
    for(float i=1.0f;i>=0.0f;i-=0.02f)
    {
    colorMatrix.Matrix00=i;
    colorMatrix.Matrix11=i;
    colorMatrix.Matrix22=i;
    colorMatrix.Matrix33=i;
    //设置色彩校正矩阵
    imageAtt.SetColorMatrix(colorMatrix,
    ColorMatrixFlag.Default,ColorAdjustType.Bitmap);
    //绘制图片
    g.DrawImage(
    bitmap, new Rectangle(0, 0, iWidth, iHeight), 
    0,0,        
    iWidth,iHeight,
    GraphicsUnit.Pixel, 
    imageAtt);
    }