1. 程式人生 > 其它 >C# MVC 生成條形碼

C# MVC 生成條形碼

技術標籤:MVC條形碼c#mvc

後臺程式碼:

using System;

using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BarcodeLib;

namespace WebAppBarcode
{
public partial class GetBarCodeImage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)

{
string strEncode = Request.QueryString[“Code”];
CreateImage(strEncode);
}

    private void CreateImage(string Code)
    {
        BarcodeLib.Barcode barcode = new BarcodeLib.Barcode()
        {
            IncludeLabel = true,
            Alignment = AlignmentPositions.CENTER,
            Width = 300,
            Height = 100,
            RotateFlipType = RotateFlipType.RotateNoneFlipNone,
            BackColor = Color.White,
            ForeColor = Color.Black,
        };

        System.Drawing.Image img = barcode.Encode(TYPE.CODE128B, Code);
        using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
        {
            img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            Response.ClearContent();
            Response.ContentType = "image/png";
            Response.BinaryWrite(ms.ToArray());
        }
    }
}

}