barcoder icon indicating copy to clipboard operation
barcoder copied to clipboard

White space around barcode image

Open Mittchel opened this issue 3 years ago • 3 comments

Hi,

First of all, amazing work @huysentruitw. We are using your barcoder library for GS1 barcodes on stickers and it works flawlessly. However, I do have one question. Whenever I generate the barcode as an image I get a white space (border?) around the barcode which takes up a lot of space in our word document which has a small size due to being a sticker. Is it possible to reduce this whitespace or remote it at all?

Mittchel avatar Feb 17 '22 13:02 Mittchel

I ran into this issue as well, but with the DataMatrix codes. we also wanted a thinner border for our application; I resorted to cloning the project locally, and making the edit needed.

suboptimal for a few reasons, but I'm not aware of any other way.

as I understand it, the width of the borders around the various barcodes are part of their specs, to help scanners identify the code. this makes me worry that there's reasons AGAINST allowing customizing them... all that being said: for our application, we're happy with thinner borders, and would appreciate the ability to customize them, as well!

BenMakesGames avatar Apr 28 '22 21:04 BenMakesGames

Hi both, this is open-source, so please feel free to discuss or add a solution through a PR (with unit-tests if possible) for adding this as a feature. When adding properties or settings, please make sure not to break anything for other users of this library (the output should remain backwards compatible).

huysentruitw avatar May 10 '22 18:05 huysentruitw

Hi, we're looking into getting rid of GDI+ and this margin is a minor annoyance. Shall we pick this library as replacement we'll definitely send a PR this way. Best regards.

Hylaean avatar May 31 '22 09:05 Hylaean

It is actually quite easy to get around the problem:

   var barcode = DataMatrixEncoder.Encode(code);
    if (noMargin)
        barcode = new NoMarginBarcode(barcode); 

internal class NoMarginBarcode : IBarcode
{
    private readonly IBarcode inner;

    public NoMarginBarcode(IBarcode inner)
    {
        this.inner = inner;
    }

    public string Content => inner.Content;
    public Bounds Bounds => inner.Bounds;
    public int Margin => 0;
    public Metadata Metadata => inner.Metadata;
    public bool At(int x, int y) => inner.At(x, y);
}

The needed changes in the API appear trivial.

Hylaean avatar Nov 24 '22 13:11 Hylaean

I have just released v2.0.0 which now uses "option" classes to pass configuration to the renderers. These new option classes now also include a property CustomMargin that allow you to override the margin on the renderer.

huysentruitw avatar Nov 28 '22 18:11 huysentruitw