将多个 TIFF 文件合并为一个 TIFF 文件 [英] Merging multiple TIFF files in one TIFF file
问题描述
我一直在尝试使用发布在以下位置的 TiffUtil 类的 mergeTiffStreams 方法:
I've been trying to use the mergeTiffStreams method of the TiffUtil class posted at:
http://kseesharp.blogspot.com/2007/12/class-for-tiff-manipulation.html
然而,就像其他人对该线程的评论一样,最终结果是我收到一个只包含我的第一个 TIFF 文件的流.我在 MemoryStream 数组中传递的其他 TIFF 不包括在内.
However, like other people have commented on that thread, the end result is that I receive a Stream that only contains my first TIFF file. The other TIFFs that I passed in the MemoryStream array are not included.
有没有其他人遇到过这个问题?如果是这样,任何建议将不胜感激.
Has anyone else run into this problem before? If so, any advice would be most appreciated.
谢谢.
[更新]
这是我目前拥有的代码.它返回的流只包含传入数组中的第一个 TIFF.
Here's the code I have at the moment. The stream that it returns only contains the first TIFF from the array passed in.
public MemoryStream mergeTiffStreams(MemoryStream[] tiffStreams)
{
if (tiffStreams == null)
throw new ArgumentNullException("tiffStreams");
Encoder enc = Encoder.SaveFlag;
ImageCodecInfo info = null;
foreach (ImageCodecInfo ice in ImageCodecInfo.GetImageEncoders())
if (ice.MimeType == "image/tiff")
info = ice;
EncoderParameters ep = new EncoderParameters(1);
ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.MultiFrame);
MemoryStream tiffStream = new MemoryStream();
Bitmap masterBitmap = new Bitmap(tiffStreams[0]);
masterBitmap.Save(tiffStream, info, ep);
ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.FrameDimensionPage);
for (int x = 1; x < tiffStreams.Length; x++)
{
masterBitmap.SaveAdd(Image.FromStream(tiffStreams[x]), ep);
}
ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.Flush);
masterBitmap.SaveAdd(ep);
return tiffStream;
}
推荐答案
您的问题可能在于您如何处理返回的流.例如,如果您想将其保存到 IO 使用:
Your problem might be in how you're handling the stream returned. If, for example, you want to save it to IO use:
File.WriteAllBytes(myPath, tiffStream.ToArray());
而不是从流中创建一个新的 Bitmap 对象.反正那是我的问题.
rather than creating a new Bitmap object from the stream. That was my problem anyway.
这篇关于将多个 TIFF 文件合并为一个 TIFF 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!