在MVC中生成条形码

问题描述 投票:0回答:1

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

<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);
    }

}

请帮帮我 ?

c# .net barcode
1个回答
1
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.