我有一张扫描的多页 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/