ZXing.net 有没有办法得到一个整数或布尔数组?
Is there a way with ZXing.net to get an integer or boolean array?
我想在我的 CAM 软件中生成二维码(或 DM 码)。对于此任务,我不需要位图,而是像一种 2D 整数数组那样的坐标。
我的意思的一个例子:
我试过 ZXing.net 但我只能创建位图。 ZXing.net 有没有办法得到一个整数或布尔数组?或者是否存在其他可以像这样编码的库?
以下是获取 BitMatrix 或 2D int 数组而不是位图的三种方法。
在我看来,第二个是最好的。不过要看你的需求了。
// first way to get a BitMatrix instead of a bitmap
var writer1 = new ZXing.QrCode.QRCodeWriter();
var bitmatrix = writer1.encode(
"<content>",
BarcodeFormat.QR_CODE,
1,
1,
new System.Collections.Generic.Dictionary<EncodeHintType, object>());
// second way to get a BitMatrix instead of a bitmap
var writer2 = new ZXing.BarcodeWriter<BitMatrix>
{
Format = BarcodeFormat.QR_CODE,
Renderer = new BitMatrixRenderer()
};
var bitmatrix2 = writer2.Write("content");
// third way to get a 2D int array instead of a bitmap
var writer3 = new ZXing.BarcodeWriter<int[,]>
{
Format = BarcodeFormat.QR_CODE,
Renderer = new BitArray2DRenderer()
};
var bitarray2D = writer3.Write("content");
public class BitMatrixRenderer : IBarcodeRenderer<BitMatrix>
{
public BitMatrix Render(BitMatrix matrix, BarcodeFormat format, string content)
{
return matrix;
}
public BitMatrix Render(BitMatrix matrix, BarcodeFormat format, string content, EncodingOptions options)
{
return matrix;
}
}
public class BitArray2DRenderer : IBarcodeRenderer<int[,]>
{
public int[,] Render(BitMatrix matrix, BarcodeFormat format, string content)
{
return Render(matrix, format, content, null);
}
public int[,] Render(BitMatrix matrix, BarcodeFormat format, string content, EncodingOptions options)
{
var result = new int[matrix.Width, matrix.Height];
for (var y = 0; y < matrix.Height; y++)
{
for (var x = 0; x < matrix.Width; x++)
{
result[x, y] = matrix[x, y] ? 1 : 0;
}
}
return result;
}
}
我想在我的 CAM 软件中生成二维码(或 DM 码)。对于此任务,我不需要位图,而是像一种 2D 整数数组那样的坐标。
我的意思的一个例子:
我试过 ZXing.net 但我只能创建位图。 ZXing.net 有没有办法得到一个整数或布尔数组?或者是否存在其他可以像这样编码的库?
以下是获取 BitMatrix 或 2D int 数组而不是位图的三种方法。 在我看来,第二个是最好的。不过要看你的需求了。
// first way to get a BitMatrix instead of a bitmap
var writer1 = new ZXing.QrCode.QRCodeWriter();
var bitmatrix = writer1.encode(
"<content>",
BarcodeFormat.QR_CODE,
1,
1,
new System.Collections.Generic.Dictionary<EncodeHintType, object>());
// second way to get a BitMatrix instead of a bitmap
var writer2 = new ZXing.BarcodeWriter<BitMatrix>
{
Format = BarcodeFormat.QR_CODE,
Renderer = new BitMatrixRenderer()
};
var bitmatrix2 = writer2.Write("content");
// third way to get a 2D int array instead of a bitmap
var writer3 = new ZXing.BarcodeWriter<int[,]>
{
Format = BarcodeFormat.QR_CODE,
Renderer = new BitArray2DRenderer()
};
var bitarray2D = writer3.Write("content");
public class BitMatrixRenderer : IBarcodeRenderer<BitMatrix>
{
public BitMatrix Render(BitMatrix matrix, BarcodeFormat format, string content)
{
return matrix;
}
public BitMatrix Render(BitMatrix matrix, BarcodeFormat format, string content, EncodingOptions options)
{
return matrix;
}
}
public class BitArray2DRenderer : IBarcodeRenderer<int[,]>
{
public int[,] Render(BitMatrix matrix, BarcodeFormat format, string content)
{
return Render(matrix, format, content, null);
}
public int[,] Render(BitMatrix matrix, BarcodeFormat format, string content, EncodingOptions options)
{
var result = new int[matrix.Width, matrix.Height];
for (var y = 0; y < matrix.Height; y++)
{
for (var x = 0; x < matrix.Width; x++)
{
result[x, y] = matrix[x, y] ? 1 : 0;
}
}
return result;
}
}