Scan with Zbar class library under Android

Source: Internet
Author: User

Program source code and executable file: Http://files.cnblogs.com/rainboy2010/zbardemo.zip

Android commonly used barcode Scanning class library has zxing and Zbaro, compared, found that zbar scanning speed faster, can identify more barcode types, the following explains how to use the Zbar implementation sweep, first put on a:

The main code is as follows:

1. Get the preview image in the Onpreviewframe method and pass it to Decodehandler to parse

@Override public  void Onpreviewframe (byte[] data, camera camera)   {if (!useoneshotpreviewcallback)  {   Camera.setpreviewcallback (NULL); } if (Previewhandler! = null)  {camera.parameters Parameters = Camera.getparameters ();    Size size = Parameters.getpreviewsize ();    Message message = Previewhandler.obtainmessage (Previewmessage, size.width,size.height, data);    Message.sendtotarget ();    Previewhandler = null; }  Else  {    log.d (TAG, "Got preview callback, but no handler for it");  }    }

2. Call the Zbar class library in the Decode method to parse the image

 private void Decode (byte[] data, int width, int height) {Image barcode = new Image (width, height, "Y800");    Rect scanimagerect = Activity.getviewfinderview (). Getscanimagerect (Height,width);    Barcode.setcrop (Scanimagerect.top, Scanimagerect.left, Scanimagerect.bottom, scanimagerect.right);    Barcode.setdata (data);    int result = Scanner.scanimage (barcode);    String strresult= "";       if (Result! = 0) {Symbolset syms = Scanner.getresults ();       for (Symbol sym:syms) {strresult=sym.getdata (). Trim ();       if (!strresult.isempty ()) {break; }}} if (!strresult.isempty ()) {Message message = Message.obtain (Activity.gethandler (), R.id.dec       ode_succeeded, strresult);//message information is transmitted, a bit around log.d (TAG, "Sending decode succeeded message ...");    Message.sendtotarget ();        } else {Message message = Message.obtain (Activity.gethandler (), r.id.decode_failed);    Message.sendtotarget (); }  }

  

Scan with Zbar class library under Android

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.