Create a QR code with Unity3d (using zxing2.2)

Source: Internet
Author: User

http://blog.csdn.net/liulala16/article/details/14521979

2013-11-08 14:53 1965 people read Comments (3) favorite reports

First download zxing.net.0.12.0.0.zip, for http://zxingnet.codeplex.com/

Then find the Unity folder in it and place the folder in Unity's project.

Script:

Using Unityengine;
Using System.Collections;
Using ZXing;
Using Zxing.qrcode;


public class Barcodecam:monobehaviour
{
void Start ()
{
encoded = new TEXTURE2D (256, 256);
Lastresult = "http://www.google.com";
}


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 Update ()
{
var textforencoding = Lastresult;
if (textforencoding! = null)
{
var color32 = Encode (textforencoding, Encoded.width, encoded.height);
Encoded. SETPIXELS32 (COLOR32);
Encoded. Apply ();
}
}


void Ongui ()
{
Gui. Drawtexture (New Rect (100,256,256), encoded);
}


public TEXTURE2D encoded;
public string Lastresult;
}

Hang the script on an empty object, run, and generate a QR code

Create a QR code with Unity3d (using zxing2.2)

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.