Implement Zbar scan QR code when the photos stored out of the way

Source: Internet
Author: User

Business Scenarioswhen a QR code scan is implemented ( with a zbar), sometimes the entire scanned image needs to be stored quietly, and (as Charles has some perverted business) that means a panoramic picture of the scanned picture. So how is the code implemented? I went to StackOverflow finally found the way to achieve!     
protected Previewcallback PREVIEWCB = new Previewcallback () {public void Onpreviewframe (byte[] data, camera camera) {                try {camera.parameters Parameters = Camera.getparameters ();                Size size = Parameters.getpreviewsize ();                Image barcode = new Image (Size.width, size.height, "Y800");                Barcode.setdata (data);                int result = Scanner.scanimage (barcode);                    if (Result! = 0) {previewing = false;                    Mcamera.setpreviewcallback (NULL);                    Mcamera.stoppreview ();                    Symbolset Symbolset = Scanner.getresults ();                        for (Symbol Sym:symbolset) {try {//Mediaplayer.start ();                        } catch (Exception ex) {ex.printstacktrace (); } if (ScanType = = Light_bar_code && sym.gettype () = = SymboL.qrcode) {supertoastutil.showtoast (Qrcodecameraactivity.this, "Only allow barcode scanning", toast.length_long);                            Finish ();                        Return } else if (ScanType = = Light_qr_code && sym.gettype ()! = Symbol.qrcode) {Supertoastuti                            L.showtoast (Qrcodecameraactivity.this, "only allow scanning QR code", Toast.length_long);                            Finish ();                        Return                        } if (sym.gettype () = = Symbol.qrcode) {CodeType = Light_qr_code;                        } else {codetype = Light_bar_code; } String Code = Sym.getdata (); try {Size previewsize = Camera.getparameters (). Getpreviewsize (); Yuvimage yuvimage=new yuvimage (data, imageformat.nv21, previewsize.width, previewsize.height, NULL); Bytearrayoutputstream BAOs = new BytearrayoutputstreAM (); Yuvimage.compresstojpeg (new Rect (0, 0, Previewsize.width, previewsize.height), and BAOs); byte[] Jdata = Baos.tobytearray (); Bitmap bmp = Bitmapfactory.decodebytearray (jdata, 0, jdata.length); Bitmaputil.savefile (Qrcodecameraactivity.this,bmp, Getlogfilenamedateformat () + ". jpg");                        catch (Exception e) {e.printstacktrace ();}                Handledecodeinternally (code);}            }} catch (Exception e) {e.printstacktrace (); }}};

  

The main use is zbar but zbar this bird thing n long not updated. There has been no good library to use, there are zxing, only these two types of scan library can be used The most finally code is here! :
try {Size previewsize = Camera.getparameters (). Getpreviewsize (); Yuvimage yuvimage=new yuvimage (data, imageformat.nv21, previewsize.width, previewsize.height, NULL); Bytearrayoutputstream BAOs = new Bytearrayoutputstream () Yuvimage.compresstojpeg (new Rect (0, 0, Previewsize.width, previewsize.height), BAOs), byte[] Jdata = Baos.tobytearray (); Bitmap bmp = Bitmapfactory.decodebytearray (jdata, 0, jdata.length); Bitmaputil.savefile (Qrcodecameraactivity.this,bmp, Getlogfilenamedateformat () + ". jpg"); catch (Exception e) {e.printstacktrace ();}

  

Implement Zbar scan QR code when the photos stored out of the way

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.