Feeds:
Posts
Comments

Posts Tagged ‘barbecue’

Barcode Encoding in JAVA

Generating barcodes, be it 1D or 2D, have never been easier. I will be using the Barbecue open source project hosted on sourceforge to generate a 1D barcode. After the barcode is generated I will decode the barcode by uploading it to a website whose service we shall use. However its also very simple to write a barcode decoder which shall be a topic of discussion later.

How to ….

First of all you need to download the Barbecue . Following are the jars added in my classpath

  • barbecue-1.5-beta1.jar
  • jdom.jar

Following is the code to generate a sample barcode

package com.datel.barcode;

import java.io.File;

import net.sourceforge.barbecue.Barcode;
import net.sourceforge.barbecue.BarcodeFactory;
import net.sourceforge.barbecue.BarcodeImageHandler;

public class GenerateBarcode {

	public static void main(String[] args) throws Exception {

		Barcode barcode = BarcodeFactory.createCode128("HelloWorld:0505124456");
        File f = new File("c:\\barcode.png");
        BarcodeImageHandler.savePNG(barcode, f);

	}

}

Now you should find a file named barcode.png in you file system in C: drive. It should look like this

Barcode

Barcode

We shall try to decode this image the easy way by uploading it to a website. Navigate to this website: ZXing This is a website hosted by the ZXing project team who have a java api for decoding barcode images. Upload your image and click Submit Query. You should see this as the output

HelloWorld:0505124456

A few words….

Even the Barbecue encoder is only beta and has been beta since May 2007. Also I really don’t comprehend why in the world these cool guys would make the Barcode class extend from javax.swing.JComponent. This really drives me mad to see such a thing but the BarcodeImageHandler class comes to the rescue. Anyways keep up the good work.

Humble Insight…

After my extensive search on the web I could not find a single open source java barcode encoder worth mentioning. I would be very much happy if any one could mention a good open source barcode encoder. But there were quite a few decoders though. Sadly to mention, if you want to encode data into barcodes on production applications you will have to rely on some commercial products out there. They are very good at what they do and are can very easily be integrated into your application. Many have facilities for resizing/rotating your image and can be very handy at times.

Using Barbecue looks all nice, simple and dandy but when you start getting requirements from your customers saying “Hey I want to put 100 MB of data in a 2D barcode” then things get hard. Although that’s a bit exaggerated, I know cases where my colleagues were asked for all weird kinds of things to be done with barcodes. To them I have only one thing to say… “Technology was made to help mankind and was not made to be abused by mankind”.

There is tremendous potential in this barcode industry and advanced encoding techniques keep coming out.

Read Full Post »