赞
踩
需要引入
using LitJson;
using ZXing;
using ZXing.QrCode;
- IEnumerator Photo()
- {
- AudioManager._instance.PlayAudio(1);
- yield return new WaitForEndOfFrame();
- Texture2D texture2D = new Texture2D(1920, 1080);
- texture2D.ReadPixels(new Rect(0, 0, 1920, 1080), 0, 0, false);
- texture2D.Apply();
- GameState._gameState = gameState.end;
- rawImage.GetChild(1).GetComponent<RawImage>().texture = texture2D;
- // JPGEncoder encoder = new JPGEncoder(texture2D, 50);
- byte[] textureByte = texture2D.EncodeToJPG();
- // encoder.doEncoding();
- // byte[] textureByte = encoder.GetBytes();
- WWWForm wWWForm = new WWWForm();
- wWWForm.AddBinaryData("photo", textureByte);
- WWW www = new WWW(Url, wWWForm);
- // UnityEngine.Networking.UnityWebRequest www = UnityEngine.Networking.UnityWebRequest.Post(Url, wWWForm);
- yield return www;
- Debug.Log(www.text);
- JsonData jsonData = JsonMapper.ToObject(www.text);
-
- string photopath = jsonData["msg"].ToString();//获取网址信息
- Texture2D ImgQR = new Texture2D(256, 256);
- ImgQR.SetPixels32(Encode(photopath, 256, 256));//将网址转成二维码
- ImgQR.Apply();
- rawImage.GetChild(2).GetComponent<RawImage>().texture = ImgQR;
- Hand.SetActive(true);
- //yield return new WaitForSeconds(30);
- //if (GameState._gameState ==gameState.end&& isback==false)
- //{
- // GameState._gameState = gameState.start;
- //}
-
- }
- public Color32[] Encode(string textForEncoding, int width, int height)
- {
- BarcodeWriter writer = new BarcodeWriter();
- writer.Format = BarcodeFormat.QR_CODE;
- writer.Options = new QrCodeEncodingOptions();
- writer.Options.Height = height;
- writer.Options.Width = width;
- writer.Options.Margin = 0;
- return writer.Write(textForEncoding);
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。