Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Barcode generator: unpredictable whitespace padding around it depending on requested Width #570

Open
samcarton opened this issue May 1, 2024 · 0 comments

Comments

@samcarton
Copy link

If you ask the barcode writer for an arbitrary width that isn't a multiple of the "default minimum" barcode width for that specific code, then you end up with unpredictable horizontal padding around the barcode.

an example:

public FileContentResult GithubExample()
{
    var code = "123456789";
    var barcodeWriter = new ZXing.ImageSharp.BarcodeWriter<Rgba32>
    {
        Format = BarcodeFormat.CODE_39,
        Options = new EncodingOptions
        {
            Height = 400,
            Width = 400,
            Margin = 0
        }
    };

    using var image = barcodeWriter.Write(code);;

    using var stream = new MemoryStream();

    var imageEncoder = new PngEncoder();
    var mime = "image/png";
    image.Save(stream, imageEncoder);

    var bytes = stream.ToArray();
    return File(bytes, mime);
}

result:
image

The workaround we currently have is to generate with Width = 1, then resize using ImageSharp after the fact. But it seems like something that ought to be handled by the generator anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant