net idautomationhc39m条形码字体生成条形码
在我的一个项目,我需要到ASP.NET网页实现条码。不幸的是,我发现的唯一方法是使用三分之一方组件。所以,我决定找到一种方法,而不使用外部元件。
使用代码
首先,你必须下载一个免费的条形码字体。在这个例子中,我使用了“idautomationhc39m”idautomation。在这个例子中,我使用了条形码39。
在WinForms应用程序,它是非常容易使用的条形码字体;只放置一个标签,并申请免费的条码字体,并分配一个值,一切准备就绪。
在Webforms,事情是不同的,因为应用程序在服务器上运行。条码字体必须驻留在服务器上。如果我们使用一个标签,条码字体位于服务器上,而不是客户端上,所以你只会看到价值,而不是条码。
好吧,让我们开始:
只需复制条码字体到Windows \字体文件夹的服务器。整个想法是创建一个文本字体(条形码),然后创建一个图像,并将其发送回客户端。
这里是一个简单的页面:
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Drawing.Imaging; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls;namespace Barcodes {/// <summary /> /// Summary description for BarCode. /// </summary /> public class BarCode : System.Web.UI.Page {private void Page_Load(object sender, System.EventArgs e){// Get the Requested code to be created.string Code = Request["code"].ToString();// Multiply the lenght of the code by 40 (just to have enough width)int w = Code.Length * 40;// Create a bitmap object of the width that we calculated and height of 100Bitmap oBitmap = new Bitmap(w,100);// then create a Graphic object for the bitmap we just created.Graphics oGraphics = Graphics.FromImage(oBitmap);// Now create a Font object for the Barcode Font// (in this case the IDAutomationHC39M) of 18 point sizeFont oFont = new Font("IDAutomationHC39M", 18);// Let's create the Point and Brushes for the barcodePointF oPoint = new PointF(2f, 2f);SolidBrush oBrushWrite = new SolidBrush(Color.Black);SolidBrush oBrush = new SolidBrush(Color.White);// Now lets create the actual barcode image// with a rectangle filled with white coloroGraphics.FillRectangle(oBrush, 0, 0, w, 100);// We have to put prefix and sufix of an asterisk (*),// in order to be a valid barcodeoGraphics.DrawString("*" + Code + "*", oFont, oBrushWrite, oPoint);// Then we send the Graphics with the actual barcodeResponse.ContentType = "image/jpeg" ;oBitmap.Save (Response.OutputStream, ImageFormat.Jpeg);} } }
测试我们的页面。只是叫HTTP:/ /本地/条码/ barcode.aspx?代码= 1234。
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="BarCodes.WebForm1" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML><HEAD><title>WebForm1</title><meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1"><meta name="CODE_LANGUAGE" Content="C#"><meta name="vs_defaultClientScript" content="JavaScript"><meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"></HEAD><body MS_POSITIONING="GridLayout"><form id="Form1" method="post" runat="server"><asp:Image id="myBarCode" runat="server"></asp:Image></form></body> </HTML>
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls;namespace BarCodes {/// <summary /> /// Summary description for WebForm1. /// </summary /> public class WebForm1 : System.Web.UI.Page{protected System.Web.UI.WebControls.Image myBarCode;private void Page_Load(object sender, System.EventArgs e){// Put user code to initialize the page heremyBarCode.ImageUrl = "BarCode.aspx?code=31231";}#region Web Form Designer generated code override protected void OnInit(EventArgs e){//// CODEGEN: This call is required by the ASP.NET Web Form Designer.//InitializeComponent();base.OnInit(e);}/// <summary /> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary /> private void InitializeComponent(){ this.Load += new System.EventHandler(this.Page_Load);}#endregion } }
net idautomationhc39m条形码字体生成条形码相关推荐
- java生成带星号条形码_Code39生成条形码加星号的解决办法以及当扫描枪扫描不到条码的解决办法 | 学步园...
这里还是引用一段别人的代码: using System; using System.Collections; using System.ComponentModel; using System.Dra ...
- java描绘条形码_java生成条形码工具类
/** * 静态内部类 * 自定义的 TextPainter, 允许定义字体,大小,文本等 * 参考底层实现:BaseLineTextPainter.getInstance() */ protecte ...
- 使用Python在Excel中批量生成条形码
2019独角兽企业重金招聘Python工程师标准>>> 最近在研究盘点机盘点的问题,其中有一部分的商品没有的条形码,就想着自个生成条形码.参考了网上的教程,关于Excel批量生成条形 ...
- Java 生成二维码 zxing生成二维码 条形码 服务端生成二维码 Java生成条形码
Java 生成二维码 zxing生成二维码 条形码 服务端生成二维码 Java生成条形码 一.关于ZXing 1.ZXing是谷歌开源的支持二维码.条形码 等图形的生成类库:支持生成.和解码功能. G ...
- excel条形码字体_在Excel中批量生成条形码,竟如此简单!
条形码可以标出物品的生产国.制造厂家.商品名称.生产日期.图书分类号.邮件起止地点.类别.日期等许多信息,因而在商品流通.图书管理.邮政管理.银行系统等许多领域都得到广泛的应用. 那么如何在Excel ...
- java用JBarcode组件生成条形码(支持自定义字体及颜色)
前言: JBarcode入门教程我就不写了,可以参考:点击打开链接 我的这篇教程和上篇博客的不同之处: 1 上篇博客直接生成二维码图片放到d盘的某个文件夹下,我的二维码生成二维码后直接用Base64编 ...
- java用JBarcode组件生成条形码(支持自定义字体及颜色),图文详解之2-1
前言: JBarcode入门教程我就不写了,可以参考:点击打开链接 我的这篇教程和上篇博客的不同之处: 1 上篇博客直接生成二维码图片放到d盘的某个文件夹下,我的二维码生成二维码后直接用Base64编 ...
- php tp5生成条形码,thinkphp5 + barcode 生成条形码
2.解压放到"E:phpstudyPHPTutorialWWWguahaovendor下",其中class文件是所有的类文件,生成条形码就是调用文件夹里的类,font文件是字体,i ...
- pHp封装成vue,vue.js生成条形码的方法
本文主要和大家分享vue.js生成条形码的方法,主要以代码的形式和大家分享,希望能帮助到大家. 1.下载插件npm install @xkeshi/vue-barcode //下载条形码插件 2.在m ...
- C#-利用ZPL语言完毕条形码的生成和打印
近期由于公司项目的须要,研究了一项对我来说算是新的技术-条形码的生成和打印.由于之前没有接触过这方面的知识,所以刚開始还有点小迷茫和小兴奋,只是一步一步来,问题总会解决的.如今来总结一下做条形码 ...
最新文章
- 第十九课.隐马尔科夫模型
- 图解在emu8086中学习几条汇编语言常用语句
- DotNet软件开发框架
- 前端学习(3245):react的生命周期getDeriveStateFromProps
- access注入漏洞
- 飞秋教程:日程安排记事提醒
- spring AOP注解实现
- Python中的split()和rsplit()的使用
- R与Python手牵手:数据框的构建、读取与基本描述
- 智鼎逻辑推理题及答案_2020常见校招笔试题型解析
- 微信开发工具小程序获取手机号失败
- POJ-1149网络流
- 幼儿园php源码,v2.8XYCMS幼儿园建站系统
- 【Redis-6.0.8】Redis中的RAX
- 关于社会认同和从众心理——从连环校园凶杀及连环跳楼说起
- prisma orm_如何使用Node.js和Prisma构建GraphQL服务器
- 好文分享 努力从何时开始都不晚 跟自己比 不断进步
- 时间格式 年月日时分秒毫秒
- Bugku-杰瑞的下午茶
- Android项目——电话拨号器