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