日期:2014-05-18  浏览次数:20952 次

在线等答案!
C# code
            bool b_Flag = false;
            if (Directory.Exists(s_FolderPath))
            {
                System.Drawing.Imaging.Encoder enc = System.Drawing.Imaging.Encoder.SaveFlag;
                EncoderParameters ep = null;
                ImageCodecInfo info = GetEncoderInfo("image/tiff");

                foreach (string FileName in Directory.GetFiles(s_FolderPath))
                {
                    string s_FileClass = GetFileType(FileName);
                    switch (s_FileClass)
                    {
                        case "6677":
                        case "255216":
                        case "7173":
                        case "7373":
                            b_Flag = false;
                            using (Image image = Image.FromFile(FileName))
                            {
                                FrameDimension Myguid = new FrameDimension(image.FrameDimensionsList[0]);
                                int Count = image.GetFrameCount(Myguid);
                                if (Count > 1)
                                {
                                    for (int i = 0; i < Count; i++)
                                    {
                                        b_Flag = true;
                                        image.SelectActiveFrame(Myguid, i);
                                        if (image.PixelFormat == PixelFormat.Format1bppIndexed)
                                        {
                                            ep = new EncoderParameters(3);
                                            ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Compression, (long)EncoderValue.CompressionCCITT4);
                                            ep.Param[1] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 0L);
                                            ep.Param[2] = new EncoderParameter(System.Drawing.Imaging.Encoder.ColorDepth, 1L);
                                        }
                                        else
                                        {
                                            ep = new EncoderParameters(1);
                                            ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Compression, (long)EncoderValue.CompressionLZW);
                                        }
                                        using (Bitmap bitmap = new Bitmap(image, image.Width, image.Height))
                                        {
                                            BitmapData bmData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
                                            bitmap.UnlockBits(bmData);
                                            bitmap.Save(FileName.Substring(0, FileName.LastIndexOf(".")) + "_" + i.ToString() + ".tif",info,ep);
                                        }
                                    }
                                }
                            }
                            if (b_Flag)
                            {
                                File.Delete(FileName);
                            }
                            break;
                        default:
                            break;
                    }
                }
            }


压缩Tif格式的代码,在本机运行没有任何问题,部署到服务器上就报错:A generic error occurred in GDI+.框架是4.0

------解决方案--------------------
在你绘图的地方加一些调试信息吧,网上有很多关于这个错误的解决办法,不知道适不适合你,http://www.cnblogs.com/johnz/archive/2008/03/06/1092931.html
------解决方案--------------------
创建Index or Non-Indexed Image , 用Graphics.DrawImage() 来copy Image到一