.net - 拆分多页 TIFF 图像 - 使用 .NET 和 IronPython

标签 .net image-processing split ironpython tiff

我有一张扫描的多页 TIFF 图像,需要将每一页拆分成单独的文件。

这很容易通过利用 .NET 框架和 C# 来实现,但是由于我没有在我使用的机器上安装所有开发工具,所以我选择使用 IronPython(通过 ipy.exe)来快速编写处理逻辑脚本。

使用 Stack Overflow 作为“博客”引擎,我将回答我自己的问题。欢迎提出意见、建议、替代方案等!

最佳答案

这是执行此操作的一种方法 - 根据需要进行调整。


import clr
clr.AddReference("System.Drawing")

from System.Drawing import Image
from System.Drawing.Imaging import FrameDimension
from System.IO import Path

# sourceFilePath - The full path to the tif image on disk (e.g path = r"C:\files\multipage.tif")
# outputDir - The directory to store the individual files.  Each output file is suffixed with its page number.
def splitImage(sourceFilePath, outputDir):
     img = Image.FromFile(sourceFilePath)

     for i in range(0, img.GetFrameCount(FrameDimension.Page)):

         name = Path.GetFileNameWithoutExtension(sourceFilePath)
         ext = Path.GetExtension(sourceFilePath)
         outputFilePath = Path.Combine(outputDir, name + "_" + str(i+1) + ext)

         frameDimensionId = img.FrameDimensionsList[0]
         frameDimension = FrameDimension(frameDimensionId)

         img.SelectActiveFrame(frameDimension, i)
         img.Save(outputFilePath, ImageFormat.Tiff)

关于.net - 拆分多页 TIFF 图像 - 使用 .NET 和 IronPython,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1877452/

相关文章:

c# - 如何防止表单关闭时控件中的事件触发

.net - SqlCommand查询的长度有什么限制

c# - 不使用 JavaScript 验证 ASP.NET GridView 中的条目

python - 根据一些给定的引用元素插入颜色矩阵的元素

c++ - 有没有内置的方法在 C++ 中拆分字符串?

php - 在第一个出现的子字符串上只分解一次字符串

.net - .NET 有图标集合吗?

matlab - 图像膨胀错误

image-processing - 可以在重新训练 Inception 模型的图像中进行对象检测(一类)吗?

javascript - 如何将unicode字符串拆分为多个字符?