如何加载tiff图像? [英] How to load tiff image ?
问题描述
我必须开发一个基于Winforms的应用程序.在其中,我可以加载图像格式的tiff,该图像包含多个页面.
我编写了一个简单的代码将图像加载到应用程序内存中.
这是我的代码:
I have to develop a winforms based application. In it, I can load a image format tiff, this image containa multiple pages.
I wrote a simple code to load image in application memory.
Here is my code:
public string[] splitTiffPages(string sourceFile, string targetDirectory)
{
string[] returnImages;
try
{
Image sourceImage = Bitmap.FromFile(sourceFile);
Image[] sourceImages = splitTiffPages(sourceImage);
int pageCount = sourceImages.Length;
returnImages = new string[pageCount];
for (int i = 0; i < pageCount; i++)
{
FileInfo fi = new FileInfo(sourceFile);
string babyImg = targetDirectory + "\\" + fi.Name.Substring(0, (fi.Name.Length - fi.Extension.Length)) + "_PAGE" + (i + 1).ToString().PadLeft(3, '0') + fi.Extension;
sourceImages[i].Save(babyImg);
returnImages[i] = babyImg;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
returnImages = null;
}
return returnImages;
}
我的代码引发异常:
1.参数无效.
2.内存不足
如果单击我的tiff文件,它将没有可用的预览,我只能在irfan查看器和fstone查看器中看到tiff文件,这些是第三方工具.
注意:我的tiff文件已扫描了多页图像
在此先感谢.
My code throws exceptions:
1. parameter is not valid.
2. out of memory
If I click on my tiff file, it will shows no preview available, I am seeing tiff file only in irfan viewer and fstone viewer these are third party tools.
Note: my tiff file has scanned image with multiple pages
Thanks in advance.
推荐答案
哪一行引发了错误?您可以先用一个图像尝试代码吗?
What line is throwing the error? Can you try your code with a single image first?
这对您有帮助,
一个简单的TIFF管理类 [
This would be helpful to you,
A simple TIFF management class[^]
--
Mark as answer if it helps
这篇关于如何加载tiff图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!