如何在C#中使用IDAutomationHC39M [英] How to use IDAutomationHC39M in C#

查看:108
本文介绍了如何在C#中使用IDAutomationHC39M的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用TextBox和Button click在C#和asp.net中使用IDAutomationHC39M.当我输入ID号并单击按钮时,它应该在带有条形码的Zebra打印机中打印...

I want to use IDAutomationHC39M in C# and asp.net using TextBox and Button click . when i enter ID number and click button it should print in Zebra Printing Machine with Barcode...

推荐答案

我应该放在路径什么位置和imgPath"
public void CreateBarcode(string data) {
    imgPath = string.Format("{0}{1}.png", path, data);
    Bitmap barcode = new Bitmap(1, 1);
    Font threeOfNine = new Font("IDAutomationHC39M", 60,
        System.Drawing.FontStyle.Regular,
        System.Drawing.GraphicsUnit.Point);
    Graphics graphics = Graphics.FromImage(barcode);
    SizeF dataSize = graphics.MeasureString(data, threeOfNine);
    barcode = new Bitmap(barcode, dataSize.ToSize());
    graphics = Graphics.FromImage(barcode);
    graphics.Clear(Color.White);
    graphics.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;
    graphics.DrawString(data, threeOfNine, new SolidBrush(Color.Black), 0, 0);
    graphics.Flush();
    threeOfNine.Dispose();
    graphics.Dispose();
    barcode.Save(imgPath);
}




我假设您是从网站上获得此代码的,并且不必费心去查看它的功能.

该代码片段在Image类实例中创建条形码,并将其保存到文件中-从您不想执行的描述中,您只想打印条形码.
因此,有两种方法可以做到这一点:
1)删除所有对路径的引用,而不是保存位图,而是将其作为图像返回到您的应用程序,然后将其直接打印到您的打印上下文或PrintDocument中.
2)使用其中一些代码将条形码直接打印到您的打印上下文或PrintDocument中.

后者将为您带来更好的结果,因为条形码将以适合于实际打印作业的分辨率进行打印,而不是最初以随机"位图分辨率进行打印,然后重新绘制为实际打印分辨率,这将引入两种伪像和错误会降低最终条形码的可读性.




I assume that you got this code from a website, and haven''t bothered too much to look at what it does.

That code fragment creates a barcode in an Image class instance, and saves it to a file - from your description you don''t want to do that, you just want to print the barcode.
So, there are two ways to do this:
1) Remove all references to path, and instead of Saving the bitmap, return it to your application as an Image and print that directly onto your print context, or PrintDocument.
2) Use some of that code to print the barcode directly onto your print context or PrintDocument.

The latter will give you better results, as the barcode will be printed at a suitable resolution for teh actual print job, instead of being printed initially to a "random" bitmap resolution, then redrawn to the actual print resolution, which will introduce both artefacts and errors which will degrade the readability of the final barcode.


这篇关于如何在C#中使用IDAutomationHC39M的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆