【发布时间】:2014-06-09 07:49:59
【问题描述】:
我在 c# (.net framework 4.0) 中创建了用于创建多页 TIFF 文件的 windows 服务。 Windows servis 监视目录并将目录中的单页 TIFF 文件合并或拆分为多页 TIFF 文件。服务正在 Windows 2012 服务器上运行。
当我在另一个图像应用程序(例如 Irfan)中打开并保存由上述服务创建的 TIFF 文件时。保存的文件较小。在 Irfan 中,我以与原始文件相同的分辨率和压缩方式保存它。当我在资源管理器中比较文件的属性时,它们具有相同的尺寸、dpi 和压缩类型。
例如我在 .NET 中创建的多页 Tiff 文件有 426kB,当我在 Irfan 中打开并保存同一个文件时,它有 407kB。大约有 20kB 的差异。只有一个文件并不重要,但我在目录中有 60 万个文件:(
对于 TIFF 创建,我使用 System.Windows.Media.Imaging 它应该比 System.Drawing.Imaging (GDI+) 更好。
...
// load frontside of document
decoder = new TiffBitmapDecoder(imageStreamSource,BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
bitmapSourceFrontSide = decoder.Frames[currentFrame];
// load backside of document
//...
encoder = new TiffBitmapEncoder();
encoder.Compression = TiffCompressOption.Ccitt4;
CroppedBitmap tiffPage;
//...
// TIFF image can be divided to multipage tiff
tiffPage = new CroppedBitmap(bitmapSourceFrontSide, new Int32Rect(pagePosition, 0, pageFrameWidth, (int)bitmapSourceFrontSide.PixelHeight));
encoder.Frames.Add(BitmapFrame.Create(tiffPage));
if (bitmapSourceBackSide != null)
{
tiffPage = new CroppedBitmap(bitmapSourceBackSide, new Int32Rect(pagePosition, 0, pageFrameWidth, (int)bitmapSourceBackSide.PixelHeight));
encoder.Frames.Add(BitmapFrame.Create(tiffPage));
}
//... created and add all pages to tiff file let's save it
using(FileStream stream = new FileStream(FileName, FileMode.Create))
{
encoder.Save(stream);
}
你知道为什么在 .NET 中创建的 TIFF 文件会更大吗?
谢谢
【问题讨论】:
-
.net 可能会在文件中添加其他元数据。像 tiff 这样的图像有一个元数据部分,用于 GPS 信息等。如果你在优化器上运行,它应该减小文件的大小,即删除元数据。
标签: c# tiff filesize multipage