我现在把gif格式转换成png,其中有些颜色变透明了,谁知道大概是那一块出错了啊讲下原理也可以

解决方案 »

  1.   

    呵呵,楼主这个问题还没解决? 那是第三方控件写的有问题,不用给它找错了.用自己的源代码就行了.
    格式转化很容易的,一行代码.private void button22_Click(object sender, EventArgs e)
    {
      Image.FromFile("d:\\temp.gif").Save("d:\\temp.png", System.Drawing.Imaging.ImageFormat.Png);
      

  2.   

    gif格式转换成png格式图片,我用别人的类直接转的,可是发现里面的蓝色转成PNG以后变成透明色了,就是那一部分没有颜色了,所以不明白原理
    就想问这个
      

  3.   

    这句不行Image.FromFile("d:\\temp.gif").Save("d:\\temp.png", System.Drawing.Imaging.ImageFormat.Png)没有重载png位数,这个函数要求保存png的同时还要能保存入png8或24
      

  4.   

    再写一个重载的函数 能存8位或24位png
      

  5.   

    CxImage对象,是一组层。
    CxImage::pDib代表着背景图像,
    CxImage::pAlpha代表着透明层,
    CxImage:: pSelection代表着被选中的层,用来创建图像处理时的区域。
    RGBQUAD nBkgndColor;  // 这项用于设置背景透明度(RGB三原色透明度)
      

  6.   


    你的Image对象为8为色 保存出来就是Png8 24就是24  
    你保存到PNG图形为透明了。可能你的Image实例里的颜色ALPHA为透明了 根据Bitmap获取BitmapData 循环数据更改ALPAH的值. 如果是索引图只需要更改
    Bitmap.Palette.Entries 就可以了...
      

  7.   

    /// <summary>
        /// 
        /// </summary>
        /// <param name="BackBmp">背景</param>
        /// <param name="ForeBmp">前图</param>
        /// <param name="ForeLeft">前景left</param>
        /// <param name="ForeTop">top</param>
        /// <param name="ForeBmpWidth">width</param>
        /// <param name="ForeBmpHeight">height</param>
        /// <param name="diaphaneityKey">透明度</param>
        /// <param name="bkColor">设置自身透明度时用</param>
        /// <param name="isSelf">是否设置自身</param>
        /// <returns></returns>
        private Bitmap SetDiaphaneity(Bitmap BackBmp, Bitmap ForeBmp, int ForeLeft, int ForeTop, int ForeBmpWidth, int ForeBmpHeight, float diaphaneityKey, bool isSelf)
        {
            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, diaphaneityKey, 0},
                new float[] {0, 0, 0, 0, 1}
            };
            ForeBmp.MakeTransparent(ForeBmp.GetPixel(0, 0));
            ColorMatrix matrix = new ColorMatrix(nArray);
            ImageAttributes attributes = new ImageAttributes();
            attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
            Graphics g = Graphics.FromImage(BackBmp);
            if (isSelf) g.Clear(System.Drawing.Color.White);
            g.DrawImage(ForeBmp, new Rectangle(new Point(ForeLeft, ForeTop),new Size(ForeBmpWidth, ForeBmpHeight)), 0, 0, BackBmp.Width, BackBmp.Height, GraphicsUnit.Pixel, attributes);
            g.Dispose();
            return BackBmp;
        }
    这个应该对你有用吧。看下。