解决方案 »

  1.   

                    Bitmap bmp;
                string pathmap = "E:\\temp\\test1.bmp";//这是一张透明的图片
                System.Drawing.Image img = System.Drawing.Image.FromFile(pathmap);
                if (IsPixelFormatIndexed(img.PixelFormat))
                {
                    bmp = new Bitmap(img.Width, img.Height, PixelFormat.Format32bppArgb);
                }
                else
                {
                    bmp = new Bitmap(pathmap);
                }
                GraphicsPath path = new GraphicsPath();
                Graphics graphics = Graphics.FromImage(bmp);
                path.AddEllipse(0, 0, 300, 300);
                PathGradientBrush pthGrBrush = new PathGradientBrush(path);
                ColorBlend colorBlend = new ColorBlend();
                colorBlend.Colors = new Color[] { Color.FromArgb(128, 255, 0, 0),   Color.FromArgb(128, 255, 255, 0), Color.FromArgb(128, 0, 255, 0) };
                colorBlend.Positions = new Single[] { 0.0f, 0.4f, 1.0f };
                pthGrBrush.InterpolationColors = colorBlend;        
                graphics.CompositingQuality = CompositingQuality.GammaCorrected;
                graphics.FillEllipse(pthGrBrush, 0, 0, 300, 300);
                bmp.Save("E:\\temp\\button.gif", System.Drawing.Imaging.ImageFormat.Gif);//生成的图片除了上面有我画的圆外,原先透明的图片已变成黑色,这是为什么??
                graphics.Dispose();
                bmp.Dispose(); 上面是我测试的代码,圆是画出来了,但是背景透明的部分全部是黑色
      

  2.   

    不懂,我只是知道GIF需要使用一种任意颜色标示为透明色
      

  3.   


    学习。我知道的是,BMP格式没有Aphla值的,怎么会是透明的图片呢?
      

  4.   

    应该是GIF格式,我放代码的时候没有改过来。做了一张GIF的透明图片