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

if (_FontSize.Width > 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();

}
    }

}


复制代码 代码如下:


<%@ WebHandler Language="C#" %>

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";

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjzswj.html