如何在aspx页面中使用c#生成BarCode Code39。 [英] How To Genrate BarCode Code39 using c# in aspx page.

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

问题描述

嗨朋友们,



im正在处理项目,客户需要为那里的产品生成条形码图像。我对此一无所知。如果有的话budy知道如何生成条形码图像并将其作为图像保存到数据库中或打印出来。



感谢和问候

Hussain

Hi Friends,

i m working on project in which client need to genrate barcode image for there product.i don''t have any idea about it.if any budy know that how to genrate barcode image & save it into database as image or print it.

Thanks & Regards
Hussain

推荐答案

public void DrawingBarcode(string strNumber)
        {
            PrivateFontCollection fonts = new PrivateFontCollection();  
            //39码
            strNumber = "*" + strNumber + "*";
            fonts.AddFontFile(HttpContext.Current.Server.MapPath(".") + "/BarcodeFonts/FREE3OF9.TTF");
            FontFamily ff = new FontFamily("Free 3 of 9", fonts);         
            Font font = new Font(ff, 12);

            //设置图片大小
             System.Drawing.Image img =  new Bitmap(1, 1);
            Graphics g = Graphics.FromImage(img);
            SizeF fontSize = g.MeasureString(strNumber, font);
            int intWidth = Convert.ToInt32(fontSize.Width);
            int intHeight = Convert.ToInt32(fontSize.Height);
            g.Dispose();
            img.Dispose();

            img = new Bitmap(intWidth, intHeight);
            g = Graphics.FromImage(img);
            g.Clear(Color.White);
            g.CompositingQuality = CompositingQuality.HighQuality;
            g.SmoothingMode = SmoothingMode.HighQuality;
            g.DrawString(strNumber, font, Brushes.Black, 0, 0);
            MemoryStream stream = new MemoryStream();
            img.Save(stream, ImageFormat.Jpeg);
            HttpContext.Current.Response.ClearContent();
            HttpContext.Current.Response.ContentType = "image/Jpeg";
            HttpContext.Current.Response.BinaryWrite(stream.ToArray());
            g.Dispose();
            img.Dispose();
        }


创建Code 39条码 [ ^ ]

条码图像生成库 [ ^ ]

GenCode128-Code128条码生成器 [ ^ ]
look Creating a Code 39 Barcode[^]
Barcode Image Generation Library[^]
GenCode128 - A Code128 Barcode Generator[^]


Hussain,

如果您计划使用库生成条形码,你可以使用eit她是一个免费图书馆或商业图书馆。关于这两种情况,Codeproject上有很多文章。

请参阅下面的文章,了解关于自由生成库的示例:

ASP.NET应用程序中的条件

有关a的示例,请参阅以下文章商业条码库:

如何使用LEADTOOLS从图像中读取条形码

以上示例用于读取条形码,但该库可用于生成条形码。
Hussain,
If you plan on using a library for generating the Barcode, you can use either a free library or a commercial library. There are a lot of articles on Codeproject for both cases.
Please see the following article for a example on a free generation library:
Barcodes in ASP.NET applications
Please see the following article for a example on a commercial barcode library:
How to Read Barcodes from Images using LEADTOOLS
The above example is for reading Barcodes but the library can be used to generate Barcode.


这篇关于如何在aspx页面中使用c#生成BarCode Code39。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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