将 tiff 像素长宽比更改为正方形
我正在尝试对多页 tiff 文件执行条形码识别。 但是 tiff 文件是从传真服务器(我无法控制)发送给我的,该服务器以非方形像素长宽比保存 tiff。 这导致图像由于纵横比而被严重挤压。 我需要将 tiff 转换为方形像素长宽比,但不知道如何在 C# 中执行此操作。 我还需要拉伸图像,以便更改纵横比仍然使图像清晰可见。
有人用 C# 做过这个吗? 或者有人使用过可以执行此类过程的图像库吗?
I'm trying to perform barcode recognition on a multipage tiff file. But the tiff file is coming to me from a fax server (which I don't have control over) that saves the tiff with a non-square pixel aspect ratio. This is causing the image to be badly squashed due to the aspect ratio. I need to convert the tiff to a square pixel aspect ratio, but have no idea how to do that in C#. I'll also need to stretch the image so that changing the aspect ratio still makes the image legible.
Has anyone done this in C#? Or has anyone used an image library that will perform such a procedure?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果其他人遇到同样的问题,这是我最终解决这个恼人问题的超级简单方法。
In case anyone else out there runs into the same issue, here is the super simple way I ended up fixing this annoying issue.
哦,我忘记说了。
Bitmap.SetResolution
可能有助于解决宽高比问题。 下面的内容只是关于调整大小。请查看此页面。 它讨论了两种调整大小的机制。 我怀疑在你的情况下双线性过滤实际上是一个坏主意,因为你可能想要漂亮和单色的东西。
下面是简单的调整大小算法的副本(由 Christian Graus 编写,来自上面链接的页面),这应该是您想要的。
另一种机制是滥用
GetThumbNailImage
函数,例如 this 。 该代码保持了纵横比,但删除执行此操作的代码应该很简单。Oh, I forgot to mention.
Bitmap.SetResolution
may help with the aspect ratio issues. The below stuff is just about resizing.Check out This page. It discusses two mechanisms for resizing. I suspect in your case bilinear filtering is actually a bad idea, since you probably want things nice and monochrome.
Below is a copy of the naive resize algorithm (written by Christian Graus, from the page linked above), which should be what you want.
An alternative mechanism is to abuse the
GetThumbNailImage
function like this. That code maintains aspect ratio, but removing the code that does that should be simple.我使用了几个图像库、FreeImage(开源)和 Snowbound 来完成此操作。 (相当昂贵)FreeImage 有 ac# 包装器,Snowbound 在 .Net 程序集中可用。 两者都运作良好。
在代码中调整它们的大小应该不是不可能的,但是 2 种颜色的冲突有时对于 GDI+ 来说很尴尬。
I have done this with a couple of image libraries, FreeImage (open source) and Snowbound. (fairly expensive) FreeImage has a c# wrapper and Snowbound is available in a .Net assembly. Both work well.
Resizing them in code would shouldn't be impossible, but 2 color tiffs are sometimes awkward with GDI+.
免责声明:我在 Atalasoft 工作,
我们的 .NET 成像 SDK 可以做到这一点。 我们编写了一篇知识库文章来展示如何使用我们的产品,但是可以适配其他SDK。 基本上,您需要重新采样图像并调整 DPI。
Disclaimer: I work at Atalasoft
Our .NET imaging SDK can do this. We have written a KB article to show how using our product, but you can adapt to other SDKs. Basically you need to resample the image and adjust the DPI.