Scan QR code to load Web images

Source: Internet
Author: User

/*              #########                                     ############                                   #############                              ##  ###########                               ###  ###### #####                        ### #######   ####                            ###  ########## ####                          ####  ########### ####   ####   ###########  #####                     #####   ### ########   #####                  #####   ###          ########   ######               ######   ###  ###########   ######            ######   #### ##############  ###### #######  #####################  ######         #######  ######################  ######       #######  ###### ######### ########  ######      #######  ###### ###### #########   ######      #######    ##  ######   ######     ######      ######     #        ######    #####     #####        ######        #####     #####     ####          #####        ####      #####   ###            #####    ###        ###      #                ###       ###        ###                       ##       ###        ###                __________#_______### #_______ # # # #______________ body is a bodhi tree, the heart like a mirror, always wipe off, do not make dust. There is no bug in our future * ==============================================================================* Filename:camroc ode* Created: $time $* author:wyc* Purpose: Scanning two-dimensional images * ============================================================== ================*/usingUnityengine;usingSystem.Collections;usingUnityengine.ui;usingZXing; Public classCamrocode:monobehaviour {[Header ("UI")]     Publicimage Image;  PublicRawimage cameratexture;  PublicText txt; Privatecolor32[] data; Private BOOLIsscan; Privatewebcamtexture webcameratexture; PrivateBarcodereader Barcodereader; Private floatTimer =0; IEnumerator Start () {Barcodereader=NewBarcodereader (); yield returnapplication.requestuserauthorization (Userauthorization.webcam); if(Application.hasuserauthorization (Userauthorization.webcam)) {webcamdevice[] devices=webcamtexture.devices; stringDeviceName = devices[0].name; Webcameratexture=NewWebcamtexture (DeviceName, -, -); Cameratexture.texture=webcameratexture;            Webcameratexture.play (); Isscan=true; }    }    intwidth; voidScreenchange ()//Screen Toggle    {        if(Width = =screen.width)return; Width=Screen.width; if(Width >screen.height) {cameraTexture.transform.localEulerAngles=Vector3.zero; }        Else{cameraTexture.transform.localEulerAngles=NewVector3 (0,0, - -); }    }    voidUpdate () {if(isscan) {timer+=Time.deltatime; if(Timer >0.5f)//0.5 seconds to scan .{startcoroutine (Scanqrcode ()); Timer=0; }        }       //Screenchange ();} IEnumerator Scanqrcode () {Data=webcameratexture.getpixels32 ();        DECODEQR (Webcameratexture.width, webcameratexture.height); yield return NewWaitforendofframe (); }    Private voidDECODEQR (intWidthintheight) {        varBR =Barcodereader.decode (data, width, height); if(BR! =NULL)        {            //Txt.text = br.            Text; //Isscan = false;startcoroutine (Load (Br.        Text)); }} IEnumerator Load (stringtext) {Txt.text="being loaded"; //Request wwwwww www =NewWWW (text); yield returnwww; if(WWW! =NULL&&string. IsNullOrEmpty (Www.error)) {//Get TextureTexture2d texture =www.texture; //Create a SpriteSprite Sprite = sprite.create (texture,NewRect (0,0, Texture.width, Texture.height),NewVector2 (0.5f,0.5f)); Image.sprite=Sprite; Txt.text="Download Success"; }    }}

Scan QR code to load Web images

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.