将位图列表保存到单个Tiff中 [英] Save List of bitmaps into a single Tiff
问题描述
大家好。
我一直在尝试以编程方式操作tiff图像。这就是说我的最终产品作为列表中的单个图像加载如下:
Hi all.
I have been experimenting with manipulating tiff images programmatically. That said my final product is loaded as a list of individual images in a list like so:
List<Bitmap> images = new List<Bitmap>();
我知道图像在那里,因为我可以在图片框中显示它们。
我的问题在这里正试图整理所有图像并保存为单个多页tiff文件。
到目前为止这是我在微软网站上找到的代码:Encoder.SaveFlag Field [ ^ ]
I know the images are there as I can display them in picturebox.
My problem here is trying to collate all images and save as single multipage tiff file.
so far this is the code which I have found on the Microsoft site: Encoder.SaveFlag Field[^]
ImageCodecInfo myImageCodecInfo;
System.Drawing.Imaging.Encoder myEncoder;
EncoderParameter myEncoderParameter;
EncoderParameters myEncoderParameters;
// Get an ImageCodecInfo object that represents the TIFF codec.
myImageCodecInfo = GetEncoderInfo("image/tiff");
// Create an Encoder object based on the GUID
// for the SaveFlag parameter category.
myEncoder = System.Drawing.Imaging.Encoder.SaveFlag;
// Create an EncoderParameters object.
// An EncoderParameters object has an array of EncoderParameter
// objects. In this case, there is only one
// EncoderParameter object in the array.
myEncoderParameters = new EncoderParameters(1);
// Save the first page.
myEncoderParameter = new EncoderParameter(myEncoder, (long)EncoderValue.CompressionCCITT4);
myEncoderParameters.Param[0] = myEncoderParameter;
final_Tiff.Save(destinaton, myImageCodecInfo, myEncoderParameters);
foreach (Bitmap bmp in images)
{
// Save rest of the pages.
myEncoderParameter = new EncoderParameter(myEncoder, (long)EncoderValue.CompressionCCITT4);
myEncoderParameters.Param[0] = myEncoderParameter;
final_Tiff.SaveAdd(bmp, myEncoderParameters);
}
// Close the multiple-frame file.
myEncoderParameter = new EncoderParameter(myEncoder, (long)EncoderValue.Flush);
myEncoderParameters.Param[0] = myEncoderParameter;
final_Tiff.SaveAdd(myEncoderParameters);
麻烦发生在:
The trouble occurs at:
final_Tiff.Save(destinaton, myImageCodecInfo, myEncoderParameters);
,错误消息:对象引用未设置为对象实例。
我检查了这些值,但它们不是空的。欢迎任何建议,并提前感谢。
with error message: Object reference not set to an instance of an object.
I did check these values and they are not null. Any suggestions are welcome, and thanks in advance.
推荐答案
首先,看看这个开源库: https://thetifflibrary.codeplex.com [ ^ ]。
您可以查看源代码以查看元数据修改是否可用。它应该是。
还有一些CodeProject文章: http://www.codeproject.com/search.aspx?q=multipage+tiff+&doctypeid=1 [ ^ ]。
首先,看看这个:将图像保存到多页TIFF文件中或将图像添加到现有TIFF文件中 [ ^ ]。
另见这一篇:一个简单的TIFF管理课程 [ ^ ]。
您可以向作者询问有关解决方案的问题。
-SA
First of all, look at this open-source library: https://thetifflibrary.codeplex.com[^].
You can look at the source code to see if metadata modification is available. It should be.
There is also a number of CodeProject articles: http://www.codeproject.com/search.aspx?q=multipage+tiff+&doctypeid=1[^].
First of all, look at this one: Save images into a multi-page TIFF file or add images to an existing TIFF file[^].
See also this one: A simple TIFF management class[^].
You can ask the authors your question about the resolution.
—SA
这篇关于将位图列表保存到单个Tiff中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!