Android Long Press the QR code zxing in the recognition graph

Source: Internet
Author: User

#基于 Zxing, beginner Android code quality is not high//Long Press, read the picture through zxing, determine if there is a QR codeBigimage.setonlongclicklistener (NewView.onlongclicklistener () {@Override Publicboolean Onlongclick (View viewm) {Bitmap obmp=( (bitmapdrawable) (bigimage). getdrawable ()). Getbitmap (); intwidth =obmp.getwidth (); intHeight =obmp.getheight (); int[] data =New int[Width *height]; Obmp.getpixels (data,0, Width,0,0, width, height); Rgbluminancesource Source=Newrgbluminancesource (width, height, data); Binarybitmap Bitmap1=NewBinarybitmap (NewHybridbinarizer (source)); Qrcodereader Reader=NewQrcodereader (); Result Re=NULL; Try{re=Reader.decode (BITMAP1); } Catch(notfoundexception e) {e.printstacktrace (); } Catch(checksumexception e) {e.printstacktrace (); } Catch(FormatException e) {e.printstacktrace (); }           if(Re = =NULL) {Showalert (obmp); } Else{Showselectalert (obmp, Re.gettext ()); }           return false;  }   }); Private voidShowalert (Final Bitmap Bitmap) {alertdialog.builder Builder=NewAlertdialog.builder ( This); Builder.setmessage ("Save Picture"). Setcancelable (false). Setpositivebutton ("Determine",NewDialoginterface.onclicklistener () {@Override Public voidOnClick (Dialoginterface Dialoginterfacem,inti) {saveimagetogallery (bitmap); }}). Setnegativebutton ("Cancel",NewDialoginterface.onclicklistener () {@Override Public voidOnClick (Dialoginterface Dialoginterfacem,inti) {}});  Builder.show (); }  Private voidShowselectalert (Final Bitmap Bitmap, final String url) {alertdialog.builder Builder=NewAlertdialog.builder ( This); Builder.settitle ("Please select"); String str[]= {"Save Picture","sweep two-dimensional code"}; Builder.setitems (str,NewDialoginterface.onclicklistener () {@Override Public voidOnClick (Dialoginterface Dialoginterfacem,inti) {Switch(i) { Case 0: {saveimagetogallery (bitmap); }                   Break;  Case 1: {Intent n=NewIntent (enlargeimagevactivity. This, Detailactivity.class);                      N.putextra (Detailactivity.bundle_key_display_type, Detailactivity.webview_detail);                      N.putextra (Detailwebfragment.web_url, URL);                  StartActivity (n); }                   Break;      }          }      }); Builder.setnegativebutton ("Cancel",NewDialoginterface.onclicklistener () {@Override Public voidOnClick (Dialoginterface Dialoginterfacem,inti) {}});  Builder.show (); }
zxing 下载  [http://download.csdn.net/detail/eric19920720/9709305]

Android Long Press the QR code zxing in the recognition graph

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.