Unity 生成、识别、扫码二维码 (1) - 基于zxing.unity.dll
 demo下载地址 https://download.csdn.net/download/qq_39735878/20328497
1,生成二维码
public void Btn_CreatQr()
{
if (QrCodeStr[Nmuber].Length > 1)
{
var color32 = Encode(QrCodeStr[Nmuber], encoded.width, encoded.height);
encoded.SetPixels32(color32);
encoded.Apply();
image.texture = encoded;
}
else
{
GameObject.Find("Text_1").GetComponent<Text>().text = "没有生成信息";
}
}
private static Color32[] Encode(string textForEncoding, int width, int height)
{
var writer = new BarcodeWriter
{
Format = BarcodeFormat.QR_CODE,
Options = new QrCodeEncodingOptions
{
Height = height,
Width = width
}
};
return writer.Write(textForEncoding);
}
2,扫描,识别二维码
void ScanQRCode()
{
data = webCamTexture.GetPixels32();
Result result = barcodeReader.Decode(data, webCamTexture.width, webCamTexture.height);
if (result != null)
{
Debug.Log(result.Text);
text.text = result.Text;
IsScanning = false;
webCamTexture.Stop();
}
}
void DeviceInit()
{
WebCamDevice[] devices = WebCamTexture.devices;
string deviceName = devices[0].name;
webCamTexture = new WebCamTexture(deviceName, 400, 300);
cameraTexture.texture = webCamTexture;
webCamTexture.Play();
barcodeReader = new BarcodeReader();
}
3,项目下载地址 https://download.csdn.net/download/qq_39735878/20328497
|