使用 itextsharp 创建带有文本图像(不是 pdf)的条形码
我可以使用 itextsharp CreateDrawingImage 方法创建条形码。但我想将实际文本包含到图像中。我该怎么做?或如何使用 CreateImageWithBarcode 方法保存为图像(Jpeg/Png)?
谢谢
I am able to create barcode using itextsharp CreateDrawingImage method. But I want to include the actual text into the image. How do I do that? or How do I use CreateImageWithBarcode method to save as image (Jpeg/Png)?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
面对同样的问题,在查看 iTextSharp 源代码后,看来你不能。除了使用 CreateDrawingImage() 之外,我在调整图像大小方面也遇到了问题,它很模糊且不可读。
我最终使用了这个库(非常酷):
http://www.codeproject.com/ KB/graphics/BarcodeLibrary.aspx
EAN13 代码:
Facing the same problem and after looking in iTextSharp sources it appears you can't. Besides with CreateDrawingImage() I had problems with image resizing, it was fuzzy and unreadable.
I ended up using this library (very cool):
http://www.codeproject.com/KB/graphics/BarcodeLibrary.aspx
Code for EAN13:
这是我用来处理条形码的函数:
要使用它,您需要执行以下操作:
我最初在这里找到了实现此函数的代码:
http://forums.asp.net/t/1599409.aspx
This is the function I made to handle my BarCodes:
To use it, you would do something like this:
I originally found code to make this function here:
http://forums.asp.net/t/1599409.aspx
我有这个 GetBarcode.ashx (通用处理程序)
它保存到输出流(直接在屏幕上)和磁盘。
像这样使用它:
在 HTML 中,这是处理程序:
I Have this GetBarcode.ashx (generic handler)
it saves to the output stream (directly on screen) and to disk.
use it like this:
in your HTML and here is the handler:
您可以只用条形码在图像上绘制文本叠加层。如果您生成一维条形码,例如(Code 39、Code 128 等),则条形码会根据输入值更改其宽度,但高度是恒定值。
因此,您可以简单地计算文本的 Y 坐标和 X 坐标,并使用如下代码绘制文本(基于此中的代码答案):
或者您可以使用一些自动计算文本位置的商业组件(但如果您已经依赖 iTextsharp,您可能最好使用自己的代码)。
免责声明:我在 ByteScout 工作,该公司是 ByteScout BarCode Generator SDK 的制造商.
You may just draw the text overlay over the image with barcode. If you are generating 1D barcodes like (Code 39, Code 128 etc) then barcode changes its width based on the input value but the height is the constant value.
So you may simply calculate Y coordinate and X coordinates for the text and draw the text with the code like this (based on the code from this this answer):
or you may use some commercial components which are doing the calculation of the text position automatically (but you may be better using your own code in case you are already relying on iTextsharp).
Disclaimer: I work for ByteScout, maker of ByteScout BarCode Generator SDK.