我编写了一个代码来将单个 tiff 文件组合到多页 tiff。但输出最后带有空白页。如果输入文件是黑白的但不是彩色的 .tiff 文件,代码可以正常工作。例如,如果我给 100 个文件,作为输入输出单个 tiff 文件拿出 47 页,其余为空白。
我使用标准代码来实现此功能,以下是我的代码。有人知道为什么吗?
using (FileStream fs = new FileStream(fileNameTemp, FileMode.Append, FileAccess.Write))
{
System.Windows.Media.Imaging.TiffBitmapEncoder tifEnc = new System.Windows.Media.Imaging.TiffBitmapEncoder();
tifEnc.Compression = System.Windows.Media.Imaging.TiffCompressOption.Default;
foreach (string fileName1 in filePaths)
{
Console.WriteLine("FileName:::" + fileName1);
System.Windows.Media.Imaging.BitmapImage bmpImg = new System.Windows.Media.Imaging.BitmapImage();
bmpImg.BeginInit();
bmpImg.CacheOption = System.Windows.Media.Imaging.BitmapCacheOption.OnLoad;
bmpImg.UriSource = new Uri(fileName1);
bmpImg.EndInit();
System.Windows.Media.Imaging.FormatConvertedBitmap fcb = new System.Windows.Media.Imaging.FormatConvertedBitmap(bmpImg,
System.Windows.Media.PixelFormats.Rgb24,
System.Windows.Media.Imaging.BitmapPalettes.Halftone27,
1.0);
tifEnc.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(fcb));
}
tifEnc.Save(fs);
fs.Dispose();
}
提前致谢!