1.报错问题:宽度和高度最小256,否则会报索引越界,高于256生成的二维码扫不出来,所以宽高就写256即可
2.留白问题: Margin = 0,这个参数控制留白
private static Texture2D Encode(string content, int width, int height)
{
var writer = new BarcodeWriter
{
Format = BarcodeFormat.QR_CODE,
Options = new QrCodeEncodingOptions
{
Height = height,
Width = width,
Margin = 0, //控制边界空白
}
};
var data = writer.Write(content);
Texture2D tex = new Texture2D(width, height);
tex.SetPixels32(data);
tex.Apply();
return tex;
}
还可以生成其他颜色的、添加logo的二维码,自行百度