日期:2014-05-18 浏览次数:20952 次
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; } } }