1

I am messing around with zxing library 2.2 (is there any documentation??)

What I want to do is:

Take an existing EAN13 string, pass it to the library and get an image to use in an ImageView (or write it to internal storage and then create bitmap for imageView by myself)

Unfortunately MatrixToImageWriter only works in J2SE and not in android (because of awt?) and therefore I can't use it.

I found this article Generate barcode image in Android application

It works fine for Code128, but when i change the BarcodeFormat.CODE_128 to EAN13 I just get an empty image.

Any ideas? Are there other libraries to achieve what I want?

Thanks in advance!

Community
  • 1
  • 1
AndyB
  • 556
  • 1
  • 9
  • 25

2 Answers2

1

You are getting an empty image because the String you are passing is not in format required by "EAN-13" BarCode format.It should be of 13 digit and the last digit of which should be the checksum of first 12 digits.

You can use this link for more information regarding EAN-13 format. http://www.barcodeisland.com/ean13.phtml

I have used following function to create checksum digit of the string.

private int calculateChecksumDigit(String mMembershipId) {
    int total_sum=0;
    for(int i=0;i<mMembershipId.length();i++)
    {
        if(i%2!=0) {
            total_sum=total_sum+Integer.parseInt(""+mMembershipId.charAt(i))*3;
        }
        else
        {
            total_sum=total_sum+Integer.parseInt(""+mMembershipId.charAt(i));
        }
    }
    return 10-(total_sum%10);

}  

and then passing it as

 BarCodeGenerator.encodeAsBitmap(mMembershipId+calculateChecksumDigit(mMembershipId), BarcodeFormat.EAN_13, widthInPixels, heightInPixels);
Akash Bisariya
  • 3,855
  • 2
  • 30
  • 42
0

What's your code look like ? What happens when you step through the create code (via what you linked to)

I create datamatrix bar codes to be read by android zxlib (via camera) or by a barcode scanner (bluetooth gun), but haven't bothered to create barcodes on android (since I want to print the bar codes, easier on my dev machine).

My datamatrix create code looks like:

    MultiFormatWriter writer = new MultiFormatWriter();
    BitMatrix b = writer.encode(bitmapstr.toString(), BarcodeFormat.DATA_MATRIX, 1200, 1200);
    File f = new File(startpath + "bitmap-" + h.name + ".bmp");
    MatrixToImageWriter.writeToFile(b, "bmp", f);

As for help/docs, it's open source, so there's always that ;)

K5 User
  • 606
  • 1
  • 6
  • 10
  • Thanks for sharing your ideas. The code above works fine on JAVA SE, so I guess I'll just build a servlet and retrieve the PNGs from android via HTTP. Maybe I'll find a way to get it running under android, though, we'll see. – AndyB Oct 17 '13 at 15:17
  • OK -- when you say empty image, is the BitMatrix that the encoder returns blank ? (At the time I wrote that code, I'd also downloaded all the zxlib code so I could step through to debug some problems, but it was so long ago, I've forgotten what the problems were..) – K5 User Oct 17 '13 at 15:49
  • I didn't focus on that any longer, because of the dependency to java SE. I found another solution, which seems to work perfectly using fonts: http://www.codeproject.com/Articles/156402/Android-Generating-an-EAN13-Barcode – AndyB Oct 18 '13 at 08:26