ThEpRoGrAmMiNgNoOb
ThEpRoGrAmMiNgNoOb

Reputation: 1294

Barcode generator for small size image

I am using ZXing.net in creating barcodes. I already generated one with the use of the following code:

var content = "AAA";
var writer = new BarcodeWriter
{
    Format = BarcodeFormat.CODE_93,
    Options = new ZXing.Common.EncodingOptions
    {
        Height = 30,
        Width = 1,
        Margin = 1,
        PureBarcode = true
    }
};
var bitmap = writer.Write(content);

Now, I want to resize the barcode to 10cm but ZXing sets minimum size to the barcode depending on the character count of the content.

I tried resizing it through resizing the image file of the barcode but the image became blurry and the scanner can't read it.

Do you have any idea on what library to use that will solve my problem? Or is there any way to resize the barcode to smaller sizes through ZXing.net?

Thank you!

Upvotes: 2

Views: 4213

Answers (1)

TaW
TaW

Reputation: 54433

The quality of the printed result will depend on:

  • amount of data (size in pixels)
  • resolution of the image (dpi, ie the physical size of each pixel)
  • quality of file format

The combination of larger pixel size and large dpi resolution will result in small but crispy images.

You can calculate the amount of data needed to get an image of 2x2 inches minimum of 150dpi as 300x300 pixels. The sizes and resolutions needed and practical will depend on your printer and scanner.

The file format will also help or hurt: JPEG is meant for photographs not for b/w line art as you create. GIF or PNG are recommended.

So: Make the tool create a large enough bitmap and then scale it down to a good resolution (150dpi or better).

You can set the resolution of and image before saving it with SetResolution(dpix, dpiy).

Upvotes: 1

Related Questions