如题,
我使用一般的方法保存后,得到一个数据格式不正确的“PNG”图片,但如果我将其以24位色保存,却是正确的。请问如何将一个24位色的图片通过GDI+保存成8位色的“PNG”图片,
Thanks。

解决方案 »

  1.   

    //以下方法 是我做切割图是做的 给你参考
    //System.Drawing.Image newImage=System.Drawing.Image.FromFile(yourimgPath);
    System.Drawing.Image oldImage=System.Drawing.Image.FromFile(yourimgPath);
    Bitmap myBitmap = new Bitmap(imgWidth1,imgHeight1,System.Drawing.Imaging.PixelFormat.Format8bppIndexed );
    Graphics g = Graphics.FromImage(myBitmap);
                Rectangle rec=new Rectangle(imgLeft1,imgTop1,imgWidth1,imgHeight1);            
    g.Clear(Color.Black);

    g.DrawImage(oldImage,0,0,rec,GraphicsUnit.Pixel);

    //Response.ContentType = "image/jpeg";
                
    myBitmap.Save(newImgSrc,ImageFormat.Png);
    // 清除缓冲 

    oldImage.Dispose();
    myBitmap.Dispose();
    g.Dispose();
      

  2.   

    Response.ContentType = "image/png";
      

  3.   

    net_lover(孟子E章) 没有用,如果这样,它就报告错误了。
      

  4.   

    hertcloud(重载∮DOTNET Joyes.com) :你的方法好象也不可行哦。
    如下语句执行时有问题,调试时报告说:“Graphics不能通过带索引的图片创建”。
    Graphics g = Graphics.FromImage(myBitmap);8位色图片是带索引的,不能创建Graphics容器,呵。不知道有没有人有其它办法将24位BMP图片保存成8位的PNG图片呀?
    急等答案,谢谢先啦!