Tagliatti / NetBarcode

Barcode generation library written in C# and .NET Standard 2
MIT License
332 stars 68 forks source link

New Method: Barcode.GetByteArray(ImageFormat) #2

Closed Grauenwolf closed 6 years ago

Grauenwolf commented 6 years ago

When generating barcodes for ASP.NET Core, we need them as a Byte[] so that we can wrap them in a file content result. For example:

    public FileContentResult Code128(string barcode)
    {
        var bc = new NetBarcode.Barcode(barcode, true);
        var result = Convert.FromBase64String(bc.GetBase64Image());

        Stream stream = new MemoryStream(result);
        return new FileContentResult(result, "image/png");

    }

Currently the way this is done is by asking Barcode to concert the image into a Byte[] which is then turned into a Base64 string, after which we turn it back into a Byte[],

This new method would just omit the Base64 step.