分割多页 TIFF 图像 - 使用 .NET 和 IronPython
我有一个扫描的多页 TIFF 图像,需要将每个页面拆分为单独的文件。
通过利用 .NET 框架和 C# 很容易做到这一点,但由于我没有在我使用的计算机上安装所有开发工具,所以我选择使用 IronPython(通过 ipy.exe)来快速编写处理脚本逻辑。
使用 Stack Overflow 作为“博客”引擎,我将回答我自己的问题。欢迎提出意见、建议、替代方案等!
I had a scanned multipage TIFF image and needed to split each page out into individual files.
This is easy to do in by leveraging the .NET framework and C#, but since I did not have all the development tools installed on the machine I was using, I instead opted to use IronPython (via ipy.exe) to quickly script the processing logic.
Using Stack Overflow as a 'blog' engine, I'll provide an answer to my own question. Comments, suggestions, alternatives, etc. are welcome!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是执行此操作的一种方法 - 根据需要进行调整。
Here is one way to do this - tweak as needed.
这样做的一个缺点是图像数据被解压缩,然后在保存时重新压缩。如果您的压缩是无损的(只是时间和内存),这不是问题,但如果您对 TIFF 内的图像使用 JPEG 压缩,则会损失质量。
有多种方法可以直接使用 libtiff 来做到这一点——我不知道还有任何其他非商业工具可以做到这一点。基本上,您需要在文件中找到与图像数据相关的 TIFF 目录条目,并将它们直接复制到新的 TIFF 中,而不需要对其进行解码和重新编码。根据您想要执行的操作量,您可能需要修复条目中的偏移量(例如,如果您还引入元数据)
如果您对能够拆分、合并、删除页面或重新排序 TIFF 文档感兴趣在不损失质量的情况下(而且速度更快,使用更少的内存),请看一下我公司的产品,DotImage ,然后查看
TiffDocument
类。 这篇 CodeProject 文章介绍了如何执行此操作。One downside to doing it this way is that the image data was decompressed and then re-compressed when it was saved. This is not a problem if your compression is lossless (just time and memory), but if you are using JPEG compression for the images inside the TIFF, you will lose quality.
There are ways to do this using libtiff directly -- I don't know of any other non-commercial tools that can do it. Basically, you need to find the TIFF directory entries in the file that relate to the image data and copy them directly into a new TIFF without decoding them and reencoding. Depending on how much you want to do, you may need to fix offsets in the entries (e.g. if you are also bringing over the meta-data)
If you are interested in being able to split, merge, remove pages from or reorder TIFF documents without losing quality (and also faster and using less memory), take a look at my company's product, DotImage, and look at the
TiffDocument
class. This CodeProject article shows how to do it.