本文整理汇总了C#中ByteMatrix.set方法的典型用法代码示例。如果您正苦于以下问题:C# ByteMatrix.set方法的具体用法?C# ByteMatrix.set怎么用?C# ByteMatrix.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ByteMatrix
的用法示例。
在下文中一共展示了ByteMatrix.set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: testApplyMaskPenaltyRule2
public void testApplyMaskPenaltyRule2()
{
var matrix = new ByteMatrix(1, 1);
matrix.set(0, 0, 0);
Assert.AreEqual(0, MaskUtil.applyMaskPenaltyRule2(matrix));
matrix = new ByteMatrix(2, 2);
matrix.set(0, 0, 0);
matrix.set(1, 0, 0);
matrix.set(0, 1, 0);
matrix.set(1, 1, 1);
Assert.AreEqual(0, MaskUtil.applyMaskPenaltyRule2(matrix));
matrix = new ByteMatrix(2, 2);
matrix.set(0, 0, 0);
matrix.set(1, 0, 0);
matrix.set(0, 1, 0);
matrix.set(1, 1, 0);
Assert.AreEqual(3, MaskUtil.applyMaskPenaltyRule2(matrix));
matrix = new ByteMatrix(3, 3);
matrix.set(0, 0, 0);
matrix.set(1, 0, 0);
matrix.set(2, 0, 0);
matrix.set(0, 1, 0);
matrix.set(1, 1, 0);
matrix.set(2, 1, 0);
matrix.set(0, 2, 0);
matrix.set(1, 2, 0);
matrix.set(2, 2, 0);
// Four instances of 2x2 blocks.
Assert.AreEqual(3*4, MaskUtil.applyMaskPenaltyRule2(matrix));
}
示例2: testApplyMaskPenaltyRule1
public void testApplyMaskPenaltyRule1()
{
{
ByteMatrix matrix = new ByteMatrix(4, 1);
matrix.set(0, 0, 0);
matrix.set(1, 0, 0);
matrix.set(2, 0, 0);
matrix.set(3, 0, 0);
Assert.AreEqual(0, MaskUtil.applyMaskPenaltyRule1(matrix));
}
{ // Horizontal.
ByteMatrix matrix = new ByteMatrix(6, 1);
matrix.set(0, 0, 0);
matrix.set(1, 0, 0);
matrix.set(2, 0, 0);
matrix.set(3, 0, 0);
matrix.set(4, 0, 0);
matrix.set(5, 0, 1);
Assert.AreEqual(3, MaskUtil.applyMaskPenaltyRule1(matrix));
matrix.set(5, 0, 0);
Assert.AreEqual(4, MaskUtil.applyMaskPenaltyRule1(matrix));
}
{ // Vertical.
ByteMatrix matrix = new ByteMatrix(1, 6);
matrix.set(0, 0, 0);
matrix.set(0, 1, 0);
matrix.set(0, 2, 0);
matrix.set(0, 3, 0);
matrix.set(0, 4, 0);
matrix.set(0, 5, 1);
Assert.AreEqual(3, MaskUtil.applyMaskPenaltyRule1(matrix));
matrix.set(0, 5, 0);
Assert.AreEqual(4, MaskUtil.applyMaskPenaltyRule1(matrix));
}
}
示例3: test
public void test()
{
var qrCode = new QRCode();
// First, test simple setters and getters.
// We use numbers of version 7-H.
qrCode.Mode = Mode.BYTE;
qrCode.ECLevel = ErrorCorrectionLevel.H;
qrCode.Version = Version.getVersionForNumber(7);
qrCode.MaskPattern = 3;
Assert.AreEqual(Mode.BYTE, qrCode.Mode);
Assert.AreEqual(ErrorCorrectionLevel.H, qrCode.ECLevel);
Assert.AreEqual(7, qrCode.Version.VersionNumber);
Assert.AreEqual(3, qrCode.MaskPattern);
// Prepare the matrix.
var matrix = new ByteMatrix(45, 45);
// Just set bogus zero/one values.
for (int y = 0; y < 45; ++y)
{
for (int x = 0; x < 45; ++x)
{
matrix.set(x, y, (y + x) % 2 == 1);
}
}
// Set the matrix.
qrCode.Matrix = matrix;
Assert.AreEqual(matrix, qrCode.Matrix);
}
示例4: testApplyMaskPenaltyRule4
public void testApplyMaskPenaltyRule4()
{
{
// Dark cell ratio = 0%
ByteMatrix matrix = new ByteMatrix(1, 1);
matrix.set(0, 0, 0);
Assert.AreEqual(100, MaskUtil.applyMaskPenaltyRule4(matrix));
}
{
// Dark cell ratio = 5%
ByteMatrix matrix = new ByteMatrix(2, 1);
matrix.set(0, 0, 0);
matrix.set(0, 0, 1);
Assert.AreEqual(0, MaskUtil.applyMaskPenaltyRule4(matrix));
}
{
// Dark cell ratio = 66.67%
ByteMatrix matrix = new ByteMatrix(6, 1);
matrix.set(0, 0, 0);
matrix.set(1, 0, 1);
matrix.set(2, 0, 1);
matrix.set(3, 0, 1);
matrix.set(4, 0, 1);
matrix.set(5, 0, 0);
Assert.AreEqual(30, MaskUtil.applyMaskPenaltyRule4(matrix));
}
}
示例5: testApplyMaskPenaltyRule3
public void testApplyMaskPenaltyRule3()
{
{
// Horizontal 00001011101.
ByteMatrix matrix = new ByteMatrix(11, 1);
matrix.set(0, 0, 0);
matrix.set(1, 0, 0);
matrix.set(2, 0, 0);
matrix.set(3, 0, 0);
matrix.set(4, 0, 1);
matrix.set(5, 0, 0);
matrix.set(6, 0, 1);
matrix.set(7, 0, 1);
matrix.set(8, 0, 1);
matrix.set(9, 0, 0);
matrix.set(10, 0, 1);
Assert.AreEqual(40, MaskUtil.applyMaskPenaltyRule3(matrix));
}
{
// Horizontal 10111010000.
ByteMatrix matrix = new ByteMatrix(11, 1);
matrix.set(0, 0, 1);
matrix.set(1, 0, 0);
matrix.set(2, 0, 1);
matrix.set(3, 0, 1);
matrix.set(4, 0, 1);
matrix.set(5, 0, 0);
matrix.set(6, 0, 1);
matrix.set(7, 0, 0);
matrix.set(8, 0, 0);
matrix.set(9, 0, 0);
matrix.set(10, 0, 0);
Assert.AreEqual(40, MaskUtil.applyMaskPenaltyRule3(matrix));
}
{
// Vertical 00001011101.
ByteMatrix matrix = new ByteMatrix(1, 11);
matrix.set(0, 0, 0);
matrix.set(0, 1, 0);
matrix.set(0, 2, 0);
matrix.set(0, 3, 0);
matrix.set(0, 4, 1);
matrix.set(0, 5, 0);
matrix.set(0, 6, 1);
matrix.set(0, 7, 1);
matrix.set(0, 8, 1);
matrix.set(0, 9, 0);
matrix.set(0, 10, 1);
Assert.AreEqual(40, MaskUtil.applyMaskPenaltyRule3(matrix));
}
{
// Vertical 10111010000.
ByteMatrix matrix = new ByteMatrix(1, 11);
matrix.set(0, 0, 1);
matrix.set(0, 1, 0);
matrix.set(0, 2, 1);
matrix.set(0, 3, 1);
matrix.set(0, 4, 1);
matrix.set(0, 5, 0);
matrix.set(0, 6, 1);
matrix.set(0, 7, 0);
matrix.set(0, 8, 0);
matrix.set(0, 9, 0);
matrix.set(0, 10, 0);
Assert.AreEqual(40, MaskUtil.applyMaskPenaltyRule3(matrix));
}
}
示例6: testToString2
public void testToString2()
{
var qrCode = new QRCode
{
Mode = Mode.BYTE,
ECLevel = ErrorCorrectionLevel.H,
Version = Version.getVersionForNumber(1),
MaskPattern = 3,
};
var matrix = new ByteMatrix(21, 21);
for (int y = 0; y < 21; ++y)
{
for (int x = 0; x < 21; ++x)
{
matrix.set(x, y, (y + x) % 2 == 1);
}
}
qrCode.Matrix = matrix;
const string expected = "<<\n" +
" mode: BYTE\n" +
" ecLevel: H\n" +
" version: 1\n" +
" maskPattern: 3\n" +
" matrix:\n" +
" 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n" +
" 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1\n" +
" 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n" +
" 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1\n" +
" 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n" +
" 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1\n" +
" 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n" +
" 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1\n" +
" 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n" +
" 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1\n" +
" 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n" +
" 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1\n" +
" 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n" +
" 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1\n" +
" 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n" +
" 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1\n" +
" 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n" +
" 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1\n" +
" 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n" +
" 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1\n" +
" 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n" +
">>\n";
Assert.AreEqual(expected, qrCode.ToString());
}
示例7: embedTimingPatterns
private static void embedTimingPatterns(ByteMatrix matrix)
{
// -8 is for skipping position detection patterns (size 7), and two horizontal/vertical
// separation patterns (size 1). Thus, 8 = 7 + 1.
for (int i = 8; i < matrix.Width - 8; ++i)
{
int bit = (i + 1) % 2;
// Horizontal line.
if (isEmpty(matrix.get(i, 6)))
{
matrix.set(i, 6, bit);
}
// Vertical line.
if (isEmpty(matrix.get(6, i)))
{
matrix.set(6, i, bit);
}
}
}
示例8: embedVerticalSeparationPattern
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private static void embedVerticalSeparationPattern(int xStart, int yStart, ByteMatrix matrix) throws com.google.zxing.WriterException
private static void embedVerticalSeparationPattern(int xStart, int yStart, ByteMatrix matrix)
{
for (int y = 0; y < 7; ++y)
{
if (!isEmpty(matrix.get(xStart, yStart + y)))
{
throw new WriterException();
}
matrix.set(xStart, yStart + y, 0);
}
}
示例9: embedPositionAdjustmentPattern
// Note that we cannot unify the function with embedPositionDetectionPattern() despite they are
// almost identical, since we cannot write a function that takes 2D arrays in different sizes in
// C/C++. We should live with the fact.
private static void embedPositionAdjustmentPattern(int xStart, int yStart, ByteMatrix matrix)
{
for (int y = 0; y < 5; ++y)
{
for (int x = 0; x < 5; ++x)
{
matrix.set(xStart + x, yStart + y, POSITION_ADJUSTMENT_PATTERN[y][x]);
}
}
}
示例10: embedPositionDetectionPattern
private static void embedPositionDetectionPattern(int xStart, int yStart, ByteMatrix matrix)
{
for (int y = 0; y < 7; ++y)
{
for (int x = 0; x < 7; ++x)
{
matrix.set(xStart + x, yStart + y, POSITION_DETECTION_PATTERN[y][x]);
}
}
}
示例11: embedHorizontalSeparationPattern
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private static void embedHorizontalSeparationPattern(int xStart, int yStart, ByteMatrix matrix) throws com.google.zxing.WriterException
private static void embedHorizontalSeparationPattern(int xStart, int yStart, ByteMatrix matrix)
{
for (int x = 0; x < 8; ++x)
{
if (!isEmpty(matrix.get(xStart + x, yStart)))
{
throw new WriterException();
}
matrix.set(xStart + x, yStart, 0);
}
}
示例12: embedDarkDotAtLeftBottomCorner
// Embed the lonely dark dot at left bottom corner. JISX0510:2004 (p.46)
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private static void embedDarkDotAtLeftBottomCorner(ByteMatrix matrix) throws com.google.zxing.WriterException
private static void embedDarkDotAtLeftBottomCorner(ByteMatrix matrix)
{
if (matrix.get(8, matrix.Height - 8) == 0)
{
throw new WriterException();
}
matrix.set(8, matrix.Height - 8, 1);
}
示例13: maybeEmbedVersionInfo
// Embed version information if need be. On success, modify the matrix and return true.
// See 8.10 of JISX0510:2004 (p.47) for how to embed version information.
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: static void maybeEmbedVersionInfo(com.google.zxing.qrcode.decoder.Version version, ByteMatrix matrix) throws com.google.zxing.WriterException
internal static void maybeEmbedVersionInfo(Version version, ByteMatrix matrix)
{
if (version.VersionNumber < 7) // Version info is necessary if version >= 7.
{
return; // Don't need version info.
}
BitArray versionInfoBits = new BitArray();
makeVersionInfoBits(version, versionInfoBits);
int bitIndex = 6 * 3 - 1; // It will decrease from 17 to 0.
for (int i = 0; i < 6; ++i)
{
for (int j = 0; j < 3; ++j)
{
// Place bits in LSB (least significant bit) to MSB order.
bool bit = versionInfoBits.get(bitIndex);
bitIndex--;
// Left bottom corner.
matrix.set(i, matrix.Height - 11 + j, bit);
// Right bottom corner.
matrix.set(matrix.Height - 11 + j, i, bit);
}
}
}
示例14: embedTypeInfo
// Embed type information. On success, modify the matrix.
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: static void embedTypeInfo(com.google.zxing.qrcode.decoder.ErrorCorrectionLevel ecLevel, int maskPattern, ByteMatrix matrix) throws com.google.zxing.WriterException
internal static void embedTypeInfo(ErrorCorrectionLevel ecLevel, int maskPattern, ByteMatrix matrix)
{
BitArray typeInfoBits = new BitArray();
makeTypeInfoBits(ecLevel, maskPattern, typeInfoBits);
for (int i = 0; i < typeInfoBits.Size; ++i)
{
// Place bits in LSB to MSB order. LSB (least significant bit) is the last value in
// "typeInfoBits".
bool bit = typeInfoBits.get(typeInfoBits.Size - 1 - i);
// Type info bits at the left top corner. See 8.9 of JISX0510:2004 (p.46).
int x1 = TYPE_INFO_COORDINATES[i][0];
int y1 = TYPE_INFO_COORDINATES[i][1];
matrix.set(x1, y1, bit);
if (i < 8)
{
// Right top corner.
int x2 = matrix.Width - i - 1;
int y2 = 8;
matrix.set(x2, y2, bit);
}
else
{
// Left bottom corner.
int x2 = 8;
int y2 = matrix.Height - 7 + (i - 8);
matrix.set(x2, y2, bit);
}
}
}
示例15: embedDataBits
// Embed "dataBits" using "getMaskPattern". On success, modify the matrix and return true.
// For debugging purposes, it skips masking process if "getMaskPattern" is -1.
// See 8.7 of JISX0510:2004 (p.38) for how to embed data bits.
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: static void embedDataBits(com.google.zxing.common.BitArray dataBits, int maskPattern, ByteMatrix matrix) throws com.google.zxing.WriterException
internal static void embedDataBits(BitArray dataBits, int maskPattern, ByteMatrix matrix)
{
int bitIndex = 0;
int direction = -1;
// Start from the right bottom cell.
int x = matrix.Width - 1;
int y = matrix.Height - 1;
while (x > 0)
{
// Skip the vertical timing pattern.
if (x == 6)
{
x -= 1;
}
while (y >= 0 && y < matrix.Height)
{
for (int i = 0; i < 2; ++i)
{
int xx = x - i;
// Skip the cell if it's not empty.
if (!isEmpty(matrix.get(xx, y)))
{
continue;
}
bool bit;
if (bitIndex < dataBits.Size)
{
bit = dataBits.get(bitIndex);
++bitIndex;
}
else
{
// Padding bit. If there is no bit left, we'll fill the left cells with 0, as described
// in 8.4.9 of JISX0510:2004 (p. 24).
bit = false;
}
// Skip masking if mask_pattern is -1.
if (maskPattern != -1 && MaskUtil.getDataMaskBit(maskPattern, xx, y))
{
bit = !bit;
}
matrix.set(xx, y, bit);
}
y += direction;
}
direction = -direction; // Reverse the direction.
y += direction;
x -= 2; // Move to the left.
}
// All bits should be consumed.
if (bitIndex != dataBits.Size)
{
throw new WriterException("Not all bits consumed: " + bitIndex + '/' + dataBits.Size);
}
}