我用C#写了个上传图片的页面,需要对图片按照规定尺寸进行缩放,保存缩放后的图片。上传Gif时,出错: Stream upImageStream = ImageUpload.InputStream;//上传文件流 System.Drawing.Image orgImg = System.Drawing.Image.FromStream(upImageStream);//通过文件流获取原始图片  
Bitmap zoomImg = new Bitmap(orgImg.Width, orgImg.Height, orgImg.PixelFormat);//创建图片(位图                  
Graphics myImg = Graphics.FromImage(zoomImg);//创建Graphics
在最后一句出现问题(处理GIF 图片时候,提示无法从带有索引像素格式的图像创建 Graphics),老提示:A Graphics object cannot be created from an image that has an indexed pixel format.请问如何解决,谢谢!!我用的vs 2005 Express Edition

解决方案 »

  1.   

    如果有解决问题的源码可以 E-mail给我:[email protected]谢谢!
      

  2.   

    http://www.codeproject.com/csharp/Water_Creator.asp
    http://www.codeproject.com/csharp/water.asp
      

  3.   

    Graphics似乎不支持GIF文件格式
      

  4.   

    TO:cscer(时光之石头) 那我要缩放、切割Gif图片,应该如何解决。
      

  5.   

    一个gif是有很多帧组成的,你需要逐个分解,然后进行缩小,最后再合成。
    分解合成gif,参看
    http://www.andreas.com/faq-gif-png.html
    http://www.codeproject.com/useritems/Extract_Animated_Gif_NET.asp
    http://www.codeproject.com/dotnet/NGif.asp
      

  6.   

    TO:Knight94(愚翁)
    还是没有解决问题。
      

  7.   

    to:Knight94(愚翁)
    Graphics myImg = Graphics.FromImage(zoomImg);//创建Graphics
    在最后一句出现问题(处理GIF 图片时候,提示无法从带有索引像素格式的图像创建 Graphics),老提示:A Graphics object cannot be created from an
      

  8.   

    不要用gif图像直接生成graphics对象,处理流程:
    1、gif 分解成png或者jpg文件组;
    2、对每个png或者jpg文件进行处理;
    3、把处理好的png或者jpg文件组,进行合成一个gif。
      

  9.   

    to:Knight94(愚翁)首先对你表示感谢,问题解决了,立马结帐!
    http://www.codeproject.com/useritems/Extract_Animated_Gif_NET.asp
    这个实例在C#中你调试过吗?
    我调试的时候出现错误:
    Bitmap b = new Bitmap((Bitmap)myImg.SelectActiveFrame(ImgFrmDim, 0));就是这句,错误提示。
    Error 1 Cannot convert type 'int' to 'System.Drawing.Bitmap'。能解释一下吗?谢谢!
      

  10.   

    to:Knight94(愚翁)
    我查了一下msdn,myImg.SelectActiveFrame(ImgFrmDim, 0)的返回值就是0.那gif 分解成png或者jpg文件组如何进行。谢谢
      

  11.   

    他的代码是有些问题,你如下操作即可
    Image myImg = Image.FromFile(@"d:\test.gif");
    //Create a new FrameDimension object from this image
    System.Drawing.Imaging.FrameDimension ImgFrmDim = new System.Drawing.Imaging.FrameDimension( myImg.FrameDimensionsList[0]);
    //Determine the number of frames in the image
    //Note that all images contain at least 1 frame, but an animated GIF will contain more than 1 frame.
    int nooffrm = myImg.GetFrameCount( ImgFrmDim );for( int i = 0; i < nooffrm; i++ )
    {
    myImg.SelectActiveFrame( ImgFrmDim, i );
    myImg.Save( string.Format( @"d:\Frame{0}.jpg", i ), ImageFormat.Jpeg );
    }
      

  12.   

    To:Knight94(愚翁)
    表示感谢!