赞
踩
用到的插件是:zxing二维码插件。图片上传在阿里云。
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using ZXing;
- using ZXing.QrCode;
-
- public class Test : MonoBehaviour
- {
-
- public RawImage rawImage1;//返回二维码图片
-
- private void Start()
- {
- Photo();
- }
-
- private void Photo()
- {
- string photopath = "";//获取网址信息
- Texture2D ImgQR = new Texture2D(256, 256);
- ImgQR.SetPixels32(Encode(photopath, 256, 256));//将网址转成二维码
- ImgQR.Apply();
- rawImage1.texture = ImgQR;
-
- }
- 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 版权所有,并保留所有权利。