【发布时间】:2020-01-30 09:23:01
【问题描述】:
我想生成带有这样标志的二维码:
环境:Unity3D C#
我尝试通过互联网上的示例编写代码。
private Texture2D GenerateBarcode(string data, BarcodeFormat format, int width, int height)
{
var encodeOptions = new EncodingOptions
{
Height = height,
Width = width,
Margin = 0,
PureBarcode = false
};
encodeOptions.Hints.Add(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
BarcodeWriter writer = new BarcodeWriter
{
Format = BarcodeFormat.QR_CODE,
Options = encodeOptions
};
Color32[] pixels = writer.Write(text);
Texture2D tex = new Texture2D(width, height);
tex.SetPixels32(pixels);
tex.Apply();
return tex;
}
Q1:如何将 QR 码的填充颜色从黑色更改为绿色?
Q2:如何将二维码两侧的“黑色方块”更改为另一个类似的图形?
请帮忙。我不知道我需要做什么。
A1:derHugo
的回答
for (var i = 0; i < pixels.Length; i++){
var pixel = pixels[i];
if (pixel.r == 0 && pixel.g == 0 && pixel.b == 0)
{
pixel = Color.green;
}
else {
pixel = Color.white;
}
pixels[i] = pixel;
}
【问题讨论】:
标签: unity3d qr-code zxing generate