Google Open source project zxing (two-dimensional barcode codec) simple to use (Java version) __java

Source: Internet
Author: User
Tags image processing library

http://code.google.com/p/zxing/

Zxing (pronounced "zebra crossing") is a open-source, multi-format 1d/2d barcode image processing library implemented in Java, with ports to the other languages. We are on using the built-in camera on mobile phones to scan and decode on the barcodes, device without G with a server. However the project can be used to encode and decode barcodes on desktops and servers as.

The zxing Project is an Open-source project on barcode codec provided by Google Code.

to develop this project two times, first you need to download the Zxing1.7.zip source code in the source download list .

unpack the files and you'll see a lot of folders inside, including J2se, Android, J2me,c#, and so on. Let's take j2se as an example.

you need to use the core and J2SE folders inside. Then import into the project you created in Eclipse, in the following form:



The J2SE package provides the encoding and decoding. Java files, but because the writing is too complex, still not clear the source code of this Open-source project, or not recommended.

you created two Java files Encoder and decoder in the J2SE package. The code is as follows:

Package com.google.zxing.client.j2se;
Import Java.io.File;
Import java.io.IOException;

Import java.util.Hashtable;
Import Com.google.zxing.BarcodeFormat;
Import Com.google.zxing.EncodeHintType;
Import Com.google.zxing.MultiFormatWriter;
Import com.google.zxing.WriterException;

Import Com.google.zxing.common.BitMatrix; public class Encoder {public static void main (string[] args) {String contents = "Today, let's talk a little bit about Google Open source project--zxing (two-dimensional barcode coding

		Code) ";

		Hashtable<encodehinttype, string> hints = new Hashtable<encodehinttype, string> ();

		Hints.put (Encodehinttype.character_set, "GBK");

		Bitmatrix matrix = null;

		try {matrix = new Multiformatwriter (). Encode (contents, Barcodeformat.qr_code, MB, hints);

		catch (Writerexception e) {e.printstacktrace ();

		The file File = new file ("D://qrcodeimage.png");

		try {matrixtoimagewriter.writetofile (Matrix, PNG, file);

		catch (IOException e) {e.printstacktrace (); }

	}
}

Package com.google.zxing.client.j2se;
Import Java.awt.image.BufferedImage;
Import Java.io.File;
Import java.io.IOException;

Import java.util.Hashtable;

Import Javax.imageio.ImageIO;
Import Com.google.zxing.BinaryBitmap;
Import Com.google.zxing.DecodeHintType;
Import Com.google.zxing.LuminanceSource;
Import Com.google.zxing.MultiFormatReader;
Import com.google.zxing.NotFoundException;
Import Com.google.zxing.Result;

Import Com.google.zxing.common.HybridBinarizer;

		public class Decoder {public static void main (string[] args) {File file = new File ("D://qrcodeimage.png");

		BufferedImage bufferedimage = null;

		try {bufferedimage = imageio.read (file);

		catch (IOException e) {e.printstacktrace ();

		} luminancesource Source = new Bufferedimageluminancesource (bufferedimage);

		Binarybitmap bitmap = new Binarybitmap (new Hybridbinarizer (source));

		Hashtable<decodehinttype, string> hints = new Hashtable<decodehinttype, string> (); Hints.put (DecodehInttype.character_set, "GBK");

		result result = NULL;

		try {result = new Multiformatreader (). Decode (bitmap, hints);

		catch (Notfoundexception e) {e.printstacktrace ();

	} System.out.println (Result.tostring ());
 }

}

then you can start to edit and identify the bar code. Here is the support of Chinese.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.