Ask about the barcode size

406 views
Skip to first unread message

Yujin

unread,
Apr 29, 2018, 8:50:00 PM4/29/18
to zxing
I used Code128 and Code39 to make a small barcode.
There is a case where the barcode reader is not scanned when the barcode size is reduced to a small size.
Is there any code to add in this case?
And depending on the printer environment, can print size or scan be different?
I am really curious about these two things.
Please answer me

I read that I need to set the width and height to 1 to create the smallest barcode. So I am using the following code.

IBarcodeWriter code39writer = new ZXing.BarcodeWriter
{
Format = BarcodeFormat.CODE_39,
Options = new ZXing.Common.EncodingOptions
{
PureBarcode = true,
Height = 1,
Width = 1,
Margin = 0
}
};

var image = code39writer.Write(bps.GetText());
Bitmap bitmap = new Bitmap(image);
e.Graphics.DrawImage(bitmap, rx, ry, rw, rh);

Lachezar Dobrev

unread,
Apr 30, 2018, 6:29:20 AM4/30/18
to Yujin, zxing
This looks like ZXing.NET code. I am not sure it is still supported
by this development team, or the community.

Using 1x1 typically does return the smallest possible image, which
one can scale up as needed. I do it too, and it works very well.

A word of warning though, especially when scaling with small
non-integer scales. This typically happens when using low resolution
printers, or low resolution images for screens. Also some times when
embedding into PDF documents the resolution can be tricky to keep
high. In these cases it is better to scale with the largest integer
scale factor that is below the target scaling value. That is, if you
need to scale the image 2.5 times, it's better to scale it 2.0 times,
and leave white space around. Otherwise you end up with ±1 pixel
difference that may (with small scaling factors) distort significantly
the thin lines.
Also avoid using bilinear, bicubic or other fancy scaling
algorithms, that add grey to the image making it harder to read. The
naive nearest-neighbour ends up with the best contrast ratio, although
the ±1px problem is heaviest that way.

If it wasn't obvious this only applies to the X of 1D bar-codes. You
can scale the Y of the 1D bar-codes to whatever you like. When scaling
2D bar-codes the X and Y scale must be the same, and should also
follow the integer rule.

If you're scaling a lot (say x10, x15, x20, etc.) having fractional
scale will not be that bad.
> --
> You received this message because you are subscribed to the Google Groups "zxing" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to zxing+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages