Using Unityengine;
Using System.Collections;
Using ZXing;
Using Zxing.qrcode;
Using System;
Using System.IO;
public class Barcodecam:monobehaviour
{
Public texture2d encoded;//generates a QR code of texture2d type
public string lastresult;//The content information contained in the QR code, I used the GUID instead
public int count = 5;//generates several QR codes
void Start ()
{
Encoded = new TEXTURE2D (256, 256);
for (int i = 0; i < count; i++)
{
Guid IdKey = Guid.NewGuid ();
Lastresult = Idkey.tostring ();
var textforencoding = Lastresult;
if (textforencoding! = null)
{
var color32 = Encode (textforencoding, Encoded.width, encoded.height);
Enco Ded. SETPIXELS32 (COLOR32);
Encoded. Apply ();
Byte[] bytes = encoded. Encodetopng ();//Convert the QR code into a byte array and then save the output as a PNG image to save the generated QR code
if (! Directory.Exists (Application.datapath + "/adambieber"))//Create a build directory, or create a directory
{
Directory.CreateDirectory if it does not exist ( Application.datapath + "/adambieber");
}
String fileName = Application.datapath + "/adambieber/" + IdKey + ". png";
System.IO.File.WriteAllBytes (fileName, bytes);
}
}
}
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);
}
void Ongui ()
{
Gui. Drawtexture (New Rect (n, a, n, N), encoded);
}
}
Easycodescanner generate two-dimensional code