0

I am referencing this to generate code39 format 1D barcode using Zxing library.

Generate barcode image in Android application

I can generate the barcode. Because i will have three different codes to show in the UI. Three different codes can have different length like below:

String barcode1_data = "1234567EA";
String barcode2_data = "1234567891012388";
String barcode3_data = "123456789000100";

bitmap1 = encodeAsBitmap2(barcode1_data, BarcodeFormat.CODE_39, 800, 120);
bitmap2 = encodeAsBitmap2(barcode2_data, BarcodeFormat.CODE_39, 1200, 150);
bitmap3 = encodeAsBitmap2(barcode3_data, BarcodeFormat.CODE_39, 1200, 150);

The result UI like this: enter image description here

I would like to have the three different barcodes to have the same height, and also the width depends on the characters. In my sample code, i hard coded, but i want it to be dynamic. Is there any rule to calculate the height and width?

Community
  • 1
  • 1
rodent_la
  • 1,195
  • 4
  • 18
  • 38

1 Answers1

0

Since you're creating 1D barcode, how about download a free barcode TTF, and use it on TextView ?

I think it's easy to adjust TextView's width & height.

Community
  • 1
  • 1
RRTW
  • 3,160
  • 1
  • 35
  • 54
  • Current request is 1D barcode, but in the future, more request will come. So i prefer to use Zxing library to have more flexibility for different support. – rodent_la Aug 31 '16 at 08:25
  • Seems you can only calculate by yourself... just get screen width/height first...and it's easy to calculate your barcode's width/height. – RRTW Aug 31 '16 at 09:21
  • One way is i try and error for each character count and set for the height and width hard code for each character length. Is there any other better way? – rodent_la Aug 31 '16 at 09:34
  • If you get screen's W/H first, I think there is nothing can be wrong. Or... you may need to check Zxing's document to know if there is any API support to set FILL_PARENT. – RRTW Aug 31 '16 at 10:03