当前位置:  编程技术>.net/c#/asp.net

asp.net(C#)生成Code39条形码实例 条码枪可以扫描出

    来源: 互联网  发布时间:2014-08-25

    本文导语:  代码如下:using System;using System.Collections;using System.ComponentModel;using System.Drawing;using System.Data; namespace MSCL{    ///     /// 生成条码Code39    ///     public class Code39    {      private Hashtable m_Code39 = new Hashtable();         priva...

代码如下:

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;

namespace MSCL
{
    ///
    /// 生成条码Code39
    ///
    public class Code39
    {
      private Hashtable m_Code39 = new Hashtable();

        private byte m_Magnify = 0;
        ///
        /// 放大倍数
        ///
        public byte Magnify { get { return m_Magnify; } set { m_Magnify = value; } }

        private int m_Height = 40;
        ///
        /// 图形高
        ///
        public int Height { get { return m_Height; } set { m_Height = value; } }

        private Font m_ViewFont = null;
        ///
        /// 字体大小
        ///
        public Font ViewFont { get { return m_ViewFont; } set { m_ViewFont = value; } }

 

        public Code39()
        {

            m_Code39.Add("A", "1101010010110");
            m_Code39.Add("B", "1011010010110");
            m_Code39.Add("C", "1101101001010");
            m_Code39.Add("D", "1010110010110");
            m_Code39.Add("E", "1101011001010");
            m_Code39.Add("F", "1011011001010");
            m_Code39.Add("G", "1010100110110");
            m_Code39.Add("H", "1101010011010");
            m_Code39.Add("I", "1011010011010");
            m_Code39.Add("J", "1010110011010");
            m_Code39.Add("K", "1101010100110");
            m_Code39.Add("L", "1011010100110");
            m_Code39.Add("M", "1101101010010");
            m_Code39.Add("N", "1010110100110");
            m_Code39.Add("O", "1101011010010");
            m_Code39.Add("P", "1011011010010");
            m_Code39.Add("Q", "1010101100110");
            m_Code39.Add("R", "1101010110010");
            m_Code39.Add("S", "1011010110010");
            m_Code39.Add("T", "1010110110010");
            m_Code39.Add("U", "1100101010110");
            m_Code39.Add("V", "1001101010110");
            m_Code39.Add("W", "1100110101010");
            m_Code39.Add("X", "1001011010110");
            m_Code39.Add("Y", "1100101101010");
            m_Code39.Add("Z", "1001101101010");
            m_Code39.Add("0", "1010011011010");
            m_Code39.Add("1", "1101001010110");
            m_Code39.Add("2", "1011001010110");
            m_Code39.Add("3", "1101100101010");
            m_Code39.Add("4", "1010011010110");
            m_Code39.Add("5", "1101001101010");
            m_Code39.Add("6", "1011001101010");
            m_Code39.Add("7", "1010010110110");
            m_Code39.Add("8", "1101001011010");
            m_Code39.Add("9", "1011001011010");
            m_Code39.Add("+", "1001010010010");
            m_Code39.Add("-", "1001010110110");
            m_Code39.Add("*", "1001011011010");
            m_Code39.Add("/", "1001001010010");
            m_Code39.Add("%", "1010010010010");
            //m_Code39.Add("contentquot;, "1001001001010");
            m_Code39.Add(".", "1100101011010");
            m_Code39.Add(" ", "1001101011010");

        }

        public enum Code39Model
        {
            ///
            /// 基本类别 1234567890ABC
            ///
            Code39Normal,
            ///
            /// 全ASCII方式 +A+B 来表示小写
            ///
            Code39FullAscII
        }
        ///
        /// 获得条码图形
        ///
        /// 文字信息
        /// 类别
        /// 是否增加前后*号
        /// 图形
        public Bitmap GetCodeImage(string p_Text, Code39Model p_Model, bool p_StarChar)
        {
            string _ValueText = "";
            string _CodeText = "";
            char[] _ValueChar = null;
            switch (p_Model)
            {
                case Code39Model.Code39Normal:
                    _ValueText = p_Text.ToUpper();
                    break;
                default:
                    _ValueChar = p_Text.ToCharArray();
                    for (int i = 0; i != _ValueChar.Length; i++)
                    {
                        if ((int)_ValueChar[i] >= 97 && (int)_ValueChar[i] p_CodeImage.Width || _FontSize.Height > p_CodeImage.Height - 20)
            {
                _Graphics.Dispose();
                return;
            }
            int _StarHeight = p_CodeImage.Height - (int)_FontSize.Height;

            _Graphics.FillRectangle(Brushes.White, new Rectangle(0, _StarHeight, p_CodeImage.Width, (int)_FontSize.Height));

            int _StarWidth = (p_CodeImage.Width - (int)_FontSize.Width) / 2;

            _Graphics.DrawString(p_Text, m_ViewFont, Brushes.Black, _StarWidth, _StarHeight);

            _Graphics.Dispose();

        }
    }

}


代码如下:

using System;
using System.Web;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;

public class GetC39Handler : IHttpHandler {
    //获取Code39处理程序
    public void ProcessRequest (HttpContext context) {
        string OrderNo = context.Request.Params["OrderNo"];
        MSCL.Code39 _Code39 = new MSCL.Code39();
        _Code39.Height = 60;
        _Code39.Magnify = 0;
        _Code39.ViewFont = new Font("Arial", 12);
        System.Drawing.Image _CodeImage = _Code39.GetCodeImage(OrderNo, MSCL.Code39.Code39Model.Code39Normal, true);
        System.IO.MemoryStream _Stream = new System.IO.MemoryStream();
        _CodeImage.Save(_Stream, System.Drawing.Imaging.ImageFormat.Jpeg);
        //_CodeImage.Save(Server.MapPath("/1.jpeg"));
        //_CodeImage.Save(Server.MapPath("/1.BMP"));
        //_CodeImage.Save(Server.MapPath("/1.GIF"));

        context.Response.ContentType = "image/tiff";
        context.Response.Clear();
        context.Response.BufferOutput = true;
        context.Response.BinaryWrite(_Stream.GetBuffer());
        context.Response.Flush();
    }   
    public bool IsReusable {
        get {
            return false;
        }
    }
}


代码如下:

        //调用显示订单条码
        Image1.ImageUrl = "GetC39Handler.ashx?OrderNo=32134411";

    
 
 

您可能感兴趣的文章:

  • 用C#,asp.net 做的网站,能用Linux做服务器吗?
  • c#(asp.net)接收存储过程返回值的方法
  • c#正则过滤图片标签 asp.net正则过滤的例子
  • c#(asp.net)实现的文件下载函数
  • asp.net(c#版)添加DataRow数据列到DataTable控件
  • c#(asp.net)连接excel的实例代码
  • c#(asp.net) new与override的区别
  • asp.net(c#) 使用Rex正则来生成字符串数组的代码
  • asp.ent 图片上传数据库的代码(c#)
  • c# asp .net 动态创建sql数据库表的方法
  • c#(asp.net)生成随机数(不重复)的例子
  • c#(asp.net)访问母版页的控件、属性、方法介绍
  • c#(asp.net) 时间操作基类(支持长短日期与时间差)
  • asp.net C#检查URL是否有效的方法
  • c# UpdatePanel无刷新上传图片 asp.net无刷新上传
  • c#(asp.net)线程配置总结
  • c# asp.net 多线程实例(经典)
  • asp.net验证码代码(C#)
  • asp.net中C#获取字符串中汉字的个数的具体实现方法
  • asp.net(C#)生成无限级别菜单的代码
  • asp.net用Zxing库实现条形码输出的具体实现
  •  
    本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
    本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。












  • 相关文章推荐
  • ASP.NET之 Ajax相关知识介绍及组件图
  • 我想了解一些关于Java怎样与Asp或Asp.net结合方面在未来发展方向的问题?
  • c#/ASP.NET操作cookie(读写)代码示例
  • asp.net UrlEncode对应asp urlencode的处理方法
  • asp.net实例 定义和使用asp:AccessDataSource
  • win2008 r2 服务器环境配置(FTP/ASP/ASP.Net/PHP)
  • asp与asp.net的session共享
  • 如何在unix下发布asp?
  • 怎么让Apache支持Asp?
  • ??谁能把ASP代码改为JSP的
  • Linux平台下哪种方法实现ASP好?
  • ASP和ASP.Net共享Session解决办法
  • 通过socket和asp打交道
  • 犹豫中……,到底是选择ASP,还是JSP?
  • asp 是否 可用applet标签?帮忙!!
  • asp.net判断数据库表是否存在 asp.net修改表名的方法
  • NOSQL iis7站长之家
  • 用JAVA APPLET做的交互式网页和ASP、PHP做的相比有什么优势呢?
  • asp.net文字水印功能简单代码
  • asp里面可否使用java写的邮件,给30分.
  • asp与Jsp可否在iis中共存的问题


  • 站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,,E-mail:www_#163.com(请将#改为@)

    浙ICP备11055608号-3