Easycodescanner generate two-dimensional code

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.