当前位置:   article > 正文

unity屏幕截图分享并生成二维码_unity截图并生成二维码

unity截图并生成二维码

 需要引入

using LitJson;
using ZXing;
using ZXing.QrCode;

  1. IEnumerator Photo()
  2. {
  3. AudioManager._instance.PlayAudio(1);
  4. yield return new WaitForEndOfFrame();
  5. Texture2D texture2D = new Texture2D(1920, 1080);
  6. texture2D.ReadPixels(new Rect(0, 0, 1920, 1080), 0, 0, false);
  7. texture2D.Apply();
  8. GameState._gameState = gameState.end;
  9. rawImage.GetChild(1).GetComponent<RawImage>().texture = texture2D;
  10. // JPGEncoder encoder = new JPGEncoder(texture2D, 50);
  11. byte[] textureByte = texture2D.EncodeToJPG();
  12. // encoder.doEncoding();
  13. // byte[] textureByte = encoder.GetBytes();
  14. WWWForm wWWForm = new WWWForm();
  15. wWWForm.AddBinaryData("photo", textureByte);
  16. WWW www = new WWW(Url, wWWForm);
  17. // UnityEngine.Networking.UnityWebRequest www = UnityEngine.Networking.UnityWebRequest.Post(Url, wWWForm);
  18. yield return www;
  19. Debug.Log(www.text);
  20. JsonData jsonData = JsonMapper.ToObject(www.text);
  21. string photopath = jsonData["msg"].ToString();//获取网址信息
  22. Texture2D ImgQR = new Texture2D(256, 256);
  23. ImgQR.SetPixels32(Encode(photopath, 256, 256));//将网址转成二维码
  24. ImgQR.Apply();
  25. rawImage.GetChild(2).GetComponent<RawImage>().texture = ImgQR;
  26. Hand.SetActive(true);
  27. //yield return new WaitForSeconds(30);
  28. //if (GameState._gameState ==gameState.end&& isback==false)
  29. //{
  30. // GameState._gameState = gameState.start;
  31. //}
  32. }
  33. public Color32[] Encode(string textForEncoding, int width, int height)
  34. {
  35. BarcodeWriter writer = new BarcodeWriter();
  36. writer.Format = BarcodeFormat.QR_CODE;
  37. writer.Options = new QrCodeEncodingOptions();
  38. writer.Options.Height = height;
  39. writer.Options.Width = width;
  40. writer.Options.Margin = 0;
  41. return writer.Write(textForEncoding);
  42. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/715883
推荐阅读
相关标签
  

闽ICP备14008679号