在MVC中生成条形码

本文关键字:条形码 MVC | 更新日期: 2023-09-27 18:26:18

我正在使用BarcodeLib。我如何在控制器中使用这样的功能?我在aspx和IHttpHandler中使用了它,但如何在控制器中使用?

<img src="/StokBarkod/Barrr?barcodeText=Hello" />

/////

public ActionResult Barcode(string barcodeText)
{
    BarcodeLib.Barcode barcode = new BarcodeLib.Barcode
    {
        IncludeLabel = false,
        Alignment = BarcodeLib.AlignmentPositions.CENTER,
        LabelPosition = LabelPositions.BOTTOMCENTER,
        RotateFlipType = RotateFlipType.RotateNoneFlipNone,
        //LabelFont = new Font("Arial", 18 * 1),
        Width = 135,
        Height = 22,
        BackColor = System.Drawing.Color.White,
        ForeColor = System.Drawing.Color.Black
    };
    //var yeniKod = barcodeText.Replace("//", "%");
    System.Drawing.Image img = barcode.Encode(BarcodeLib.TYPE.CODE128, barcodeText);

    Byte[] bytdizi = new Byte[-1 + 1];
    bytdizi = (Byte[])imageToByteArray(img);
    System.IO.Stream ms = new System.IO.MemoryStream(bytdizi);
    byte[] buffer = new byte[4096];
    int byteSeq = ms.Read(buffer, 0, 4096);
    HttpContext.Current.Response.ContentType = "image/jpeg";
    while (byteSeq > 0)
    {
        HttpContext.Current.Response.OutputStream.Write(buffer, 0, byteSeq);
        byteSeq = ms.Read(buffer, 0, 4096);
    }
}

请帮帮我?

在MVC中生成条形码

使用JsBarcode。它很容易在JS中生成条形码。