Я хочу сгенерировать QR-код с lo go, например:
Среда: Unity3D C#
![image](https://user-images.githubusercontent.com/10961423/73434743-892cc700-4371-11ea-8e54-c304b72e5b13.png)
I try to write code by examples from Internet.
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: Как я могу изменить "черные квадраты" по бокам QR-кода на другую похожую фигуру?
Пожалуйста, помогите. Я понятия не имею, что мне нужно.
A1: Ответ от derHu go
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;
}