如何使用 C# 从字符串生成条形码?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1998209/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 22:31:42  来源:igfitidea点击:

How to generate barcode from a string using C#?

c#asp.netbarcode

提问by ACP

  • Is it possible to generate barcode from a string using c#?
  • Is there any builtin classes for generating barcodes in asp.net?
  • Is it possible to detect a barcode printer connected with a system?
  • 是否可以使用 c# 从字符串生成条形码?
  • asp.net 中是否有用于生成条码的内置类?
  • 是否可以检测与系统连接的条码打印机?

采纳答案by Rune Grimstad

Yep. Of course it is possible. :-)
As far as I know there are two ways to generate bar codes:

是的。当然这是可能的。:-)
据我所知,有两种方法可以生成条码:

  1. Using a special bar code font (try to google for "barcode font free")
  2. Render the bar code to an image and display that (try using the Barcode Rendering Frameworkavailable on codeplex)
  1. 使用特殊的条码字体(尝试谷歌搜索“barcode font free”)
  2. 将条形码渲染为图像并显示(尝试使用codeplex 上可用的Barcode Rendering Framework

In response to your updated question about detecting barcode printers:
I think a barcode printer will show up as a regular printer on your system. At least that is how the devices I have played with have worked.
This means that you can detect a specific barcode printer by enumerating the installed printers on the system and looking for the specified device, but in most cases I would suggest that you let the user specify the printer himself using either the standard print dialog or using a custom dialog.

针对您关于检测条码打印机的最新问题:
我认为条码打印机将在您的系统上显示为常规打印机。至少我玩过的设备是这样工作的。
这意味着您可以通过枚举系统上已安装的打印机并查找指定的设备来检测特定的条码打印机,但在大多数情况下,我建议您让用户使用标准打印对话框或使用自定义对话框。

回答by Mark Redman

Barcode fontsexist in asp.net (IE web). You could draw barcodetext to an image and display that. This could be a similar implementation to a capchacontrol.

Barcode fonts存在于asp.net (IE web) 中。您可以barcode在图像上绘制文本并显示它。这可能是与capcha控件类似的实现。

回答by AndrewD

For generating barcodes try http://www.codeproject.com/Articles/20823/Barcode-Image-Generation-Library

要生成条形码,请尝试http://www.codeproject.com/Articles/20823/Barcode-Image-Generation-Library

Allows saving to image with or without label and supports a number of formats.

允许保存为带有或不带有标签的图像,并支持多种格式。

回答by Eugene

to detect if you have printer installed then you may simply enumerate available printers using:

要检测您是否安装了打印机,那么您可以简单地使用以下方法枚举可用的打印机:

 System.Drawing.Printing.PrinterSettings.InstalledPrinters

回答by Joe Ratzer

Is it possible to generate barcodes from a string using c#?

是否可以使用 c# 从字符串生成条形码?

Yes, it is. There are quite a lot of frameworks that do it - either as a font or an image.

是的。有很多框架可以做到这一点——无论是作为字体还是图像。

Is there any built-in classes for generating barcodes in asp.net?

asp.net 中是否有用于生成条码的内置类?

No, but this c# project on githuballows a string to be converted into an image (even multiple barcode types). All you need to do then is display the image in your application, just like any other image.

不,但github 上的这个c# 项目允许将字符串转换为图像(甚至多种条形码类型)。然后您需要做的就是在您的应用程序中显示图像,就像任何其他图像一样。

Is it possible to detect a barcode printer connected with a system?

是否可以检测与系统连接的条码打印机?

Yes, in a WinForm application, for example, you could use System.Drawing.Printing.PrinterSettings.InstalledPrinters.

是的,例如,在 WinForm 应用程序中,您可以使用System.Drawing.Printing.PrinterSettings.InstalledPrinters.