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)