本文整理汇总了C#中ByteMatrix类的典型用法代码示例。如果您正苦于以下问题:C# ByteMatrix类的具体用法?C# ByteMatrix怎么用?C# ByteMatrix使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ByteMatrix类属于命名空间,在下文中一共展示了ByteMatrix类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: 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);
}
开发者ID:n1rvana,项目名称:ZXing.NET,代码行数:31,代码来源:QRCodeTestCase.cs
示例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));
}
}
开发者ID:Bogdan-p,项目名称:ZXing.Net,代码行数:35,代码来源:MaskUtilTestCase.cs
示例3: calculateMaskPenalty
// The mask penalty calculation is complicated. See Table 21 of JISX0510:2004 (p.45) for details.
// Basically it applies four rules and summate all penalties.
private static int calculateMaskPenalty(ByteMatrix matrix)
{
return MaskUtil.applyMaskPenaltyRule1(matrix)
+ MaskUtil.applyMaskPenaltyRule2(matrix)
+ MaskUtil.applyMaskPenaltyRule3(matrix)
+ MaskUtil.applyMaskPenaltyRule4(matrix);
}
开发者ID:Binjaaa,项目名称:ZXing.Net.Mobile,代码行数:9,代码来源:Encoder.cs
示例4: 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));
}
开发者ID:arumata,项目名称:zxingnet,代码行数:30,代码来源:MaskUtilTestCase.cs
示例5: buildMatrix
// Build 2D matrix of QR Code from "dataBits" with "ecLevel", "version" and "getMaskPattern". On
// success, store the result in "matrix" and return true.
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: static void buildMatrix(com.google.zxing.common.BitArray dataBits, com.google.zxing.qrcode.decoder.ErrorCorrectionLevel ecLevel, com.google.zxing.qrcode.decoder.Version version, int maskPattern, ByteMatrix matrix) throws com.google.zxing.WriterException
internal static void buildMatrix(BitArray dataBits, ErrorCorrectionLevel ecLevel, Version version, int maskPattern, ByteMatrix matrix)
{
clearMatrix(matrix);
embedBasicPatterns(version, matrix);
// Type information appear with any version.
embedTypeInfo(ecLevel, maskPattern, matrix);
// Version info appear if version >= 7.
maybeEmbedVersionInfo(version, matrix);
// Data should be embedded at end.
embedDataBits(dataBits, maskPattern, matrix);
}
开发者ID:Th3Ya0vi,项目名称:GameHouseUniverse,代码行数:15,代码来源:MatrixUtil.cs
示例6: Encode
public static BitMatrix Encode(string content, ErrorCorrectionLevel ecLevel)
{
QRCodeInternal qrInternal;
BitVector headerAndDataBits = DataEncodeUsingReferenceImplementation(content, ecLevel, out qrInternal);
// Step 6: Interleave data bits with error correction code.
BitVector finalBits = new BitVector();
EncoderInternal.interleaveWithECBytes(headerAndDataBits, qrInternal.NumTotalBytes, qrInternal.NumDataBytes, qrInternal.NumRSBlocks, finalBits);
// Step 7: Choose the mask pattern and set to "QRCodeInternal".
ByteMatrix matrix = new ByteMatrix(qrInternal.MatrixWidth, qrInternal.MatrixWidth);
int MaskPattern = EncoderInternal.chooseMaskPattern(finalBits, qrInternal.EcLevelInternal, qrInternal.Version, matrix);
// Step 8. Build the matrix and set it to "QRCodeInternal".
MatrixUtil.buildMatrix(finalBits, qrInternal.EcLevelInternal, qrInternal.Version, MaskPattern, matrix);
return matrix.ToBitMatrix();
}
开发者ID:fengdc,项目名称:QrCode.Net,代码行数:17,代码来源:DataEncodeExtensions.cs
示例7: applyMaskPenaltyRule2
/// <summary>
/// Apply mask penalty rule 2 and return the penalty. Find 2x2 blocks with the same color and give
/// penalty to them. This is actually equivalent to the spec's rule, which is to find MxN blocks and give a
/// penalty proportional to (M-1)x(N-1), because this is the number of 2x2 blocks inside such a block.
/// </summary>
internal static int applyMaskPenaltyRule2(ByteMatrix matrix)
{
int penalty = 0;
sbyte[][] array = matrix.Array;
int width = matrix.Width;
int height = matrix.Height;
for (int y = 0; y < height - 1; y++)
{
for (int x = 0; x < width - 1; x++)
{
int value = array[y][x];
if (value == array[y][x + 1] && value == array[y + 1][x] && value == array[y + 1][x + 1])
{
penalty++;
}
}
}
return N2 * penalty;
}
开发者ID:Th3Ya0vi,项目名称:GameHouseUniverse,代码行数:24,代码来源:MaskUtil.cs
示例8: CreateRawQR
public static ByteMatrix CreateRawQR(byte[] rawData, ErrorCorrectionLevel errorCorrectionLevel)
{
int versionNumber = GetSmallestVersion(rawData.Length, errorCorrectionLevel);
ZXing.QrCode.Internal.Version version = ZXing.QrCode.Internal.Version.getVersionForNumber(versionNumber);
BitArray dataBits = new BitArray();
foreach (byte b in rawData)
dataBits.appendBits(b, 8);
ZXing.QrCode.Internal.Version.ECBlocks ecBlocks = version.getECBlocksForLevel(errorCorrectionLevel);
int bytesLength = version.TotalCodewords - ecBlocks.TotalECCodewords;
terminateBits(bytesLength, dataBits);
BitArray resultBits = interleaveWithECBytes(dataBits, version.TotalCodewords, bytesLength, ecBlocks.NumBlocks);
ByteMatrix matrix = new ByteMatrix(version.DimensionForVersion, version.DimensionForVersion);
int maskPattern = chooseMaskPattern(resultBits, errorCorrectionLevel, version, matrix);
MatrixUtil.buildMatrix(resultBits, errorCorrectionLevel, version, maskPattern, matrix);
return matrix;
}
开发者ID:jefff,项目名称:animalcrossingqr,代码行数:21,代码来源:StructuredAppendQR.cs
示例9: ConvertByteMatrixToImage
private unsafe Bitmap ConvertByteMatrixToImage(ByteMatrix bm)
{
Bitmap image = CreateGrayscaleImage(bm.Width, bm.Height);
BitmapData sourceData;
sourceData = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, image.PixelFormat);
int width = sourceData.Width;
int height = sourceData.Height;
int srcOffset = sourceData.Stride - width;
byte* src = (byte*)sourceData.Scan0.ToPointer();
for (int y = 0; y < height; y++)
{
// for each pixel
for (int x = 0; x < width; x++, src++)
{
*src = (byte)bm.Array[y][x];
}
src += srcOffset;
}
image.UnlockBits(sourceData);
return image;
}
开发者ID:alt236,项目名称:Barcode-Generator-C-Sharp,代码行数:23,代码来源:barcodeCreator.cs
示例10: 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));
}
}
开发者ID:Bogdan-p,项目名称:ZXing.Net,代码行数:67,代码来源:MaskUtilTestCase.cs
示例11: applyMaskPenaltyRule1Internal
/// <summary>
/// Helper function for applyMaskPenaltyRule1. We need this for doing this calculation in both
/// vertical and horizontal orders respectively.
/// </summary>
private static int applyMaskPenaltyRule1Internal(ByteMatrix matrix, bool isHorizontal)
{
int penalty = 0;
int iLimit = isHorizontal ? matrix.Height : matrix.Width;
int jLimit = isHorizontal ? matrix.Width : matrix.Height;
sbyte[][] array = matrix.Array;
for (int i = 0; i < iLimit; i++)
{
int numSameBitCells = 0;
int prevBit = -1;
for (int j = 0; j < jLimit; j++)
{
int bit = isHorizontal ? array[i][j] : array[j][i];
if (bit == prevBit)
{
numSameBitCells++;
}
else
{
if (numSameBitCells >= 5)
{
penalty += N1 + (numSameBitCells - 5);
}
numSameBitCells = 1; // Include the cell itself.
prevBit = bit;
}
}
if (numSameBitCells > 5)
{
penalty += N1 + (numSameBitCells - 5);
}
}
return penalty;
}
开发者ID:Th3Ya0vi,项目名称:GameHouseUniverse,代码行数:38,代码来源:MaskUtil.cs
示例12: embedDataBits
/// <summary>
/// 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.
/// </summary>
/// <param name="dataBits">The data bits.</param>
/// <param name="maskPattern">The mask pattern.</param>
/// <param name="matrix">The matrix.</param>
public 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[xx, y]))
{
continue;
}
int bit;
if (bitIndex < dataBits.Size)
{
bit = dataBits[bitIndex] ? 1 : 0;
++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 = 0;
}
// Skip masking if mask_pattern is -1.
if (maskPattern != -1)
{
if (MaskUtil.getDataMaskBit(maskPattern, xx, y))
{
bit ^= 0x1;
}
}
matrix[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);
}
}
开发者ID:n1rvana,项目名称:ZXing.NET,代码行数:67,代码来源:MatrixUtil.cs
示例13: maybeEmbedVersionInfo
/// <summary>
/// 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.
/// </summary>
/// <param name="version">The version.</param>
/// <param name="matrix">The matrix.</param>
public 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.
var bit = versionInfoBits[bitIndex] ? 1 : 0;
bitIndex--;
// Left bottom corner.
matrix[i, matrix.Height - 11 + j] = bit;
// Right bottom corner.
matrix[matrix.Height - 11 + j, i] = bit;
}
}
}
开发者ID:n1rvana,项目名称:ZXing.NET,代码行数:31,代码来源:MatrixUtil.cs
示例14: embedTypeInfo
/// <summary>
/// Embed type information. On success, modify the matrix.
/// </summary>
/// <param name="ecLevel">The ec level.</param>
/// <param name="maskPattern">The mask pattern.</param>
/// <param name="matrix">The matrix.</param>
public 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".
int bit = typeInfoBits[typeInfoBits.Size - 1 - i] ? 1 : 0;
// 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[x1, y1] = bit;
if (i < 8)
{
// Right top corner.
int x2 = matrix.Width - i - 1;
int y2 = 8;
matrix[x2, y2] = bit;
}
else
{
// Left bottom corner.
int x2 = 8;
int y2 = matrix.Height - 7 + (i - 8);
matrix[x2, y2] = bit;
}
}
}
开发者ID:n1rvana,项目名称:ZXing.NET,代码行数:38,代码来源:MatrixUtil.cs
示例15: embedBasicPatterns
/// <summary>
/// Embed basic patterns. On success, modify the matrix and return true.
/// The basic patterns are:
/// - Position detection patterns
/// - Timing patterns
/// - Dark dot at the left bottom corner
/// - Position adjustment patterns, if need be
/// </summary>
/// <param name="version">The version.</param>
/// <param name="matrix">The matrix.</param>
public static void embedBasicPatterns(Version version, ByteMatrix matrix)
{
// Let's get started with embedding big squares at corners.
embedPositionDetectionPatternsAndSeparators(matrix);
// Then, embed the dark dot at the left bottom corner.
embedDarkDotAtLeftBottomCorner(matrix);
// Position adjustment patterns appear if version >= 2.
maybeEmbedPositionAdjustmentPatterns(version, matrix);
// Timing patterns should be embedded after position adj. patterns.
embedTimingPatterns(matrix);
}
开发者ID:n1rvana,项目名称:ZXing.NET,代码行数:22,代码来源:MatrixUtil.cs
示例16: maybeEmbedPositionAdjustmentPatterns
/// <summary>
/// Embed position adjustment patterns if need be.
/// </summary>
/// <param name="version">The version.</param>
/// <param name="matrix">The matrix.</param>
private static void maybeEmbedPositionAdjustmentPatterns(Version version, ByteMatrix matrix)
{
if (version.VersionNumber < 2)
{
// The patterns appear if version >= 2
return;
}
int index = version.VersionNumber - 1;
int[] coordinates = POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLE[index];
int numCoordinates = POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLE[index].Length;
for (int i = 0; i < numCoordinates; ++i)
{
for (int j = 0; j < numCoordinates; ++j)
{
int y = coordinates[i];
int x = coordinates[j];
if (x == -1 || y == -1)
{
continue;
}
// If the cell is unset, we embed the position adjustment pattern here.
if (isEmpty(matrix[x, y]))
{
// -2 is necessary since the x/y coordinates point to the center of the pattern, not the
// left top corner.
embedPositionAdjustmentPattern(x - 2, y - 2, matrix);
}
}
}
}
开发者ID:n1rvana,项目名称:ZXing.NET,代码行数:35,代码来源:MatrixUtil.cs
示例17: ZXEncode
private void ZXEncode(string content, int option)
{
System.String encoding = QRCodeConstantVariable.DefaultEncoding;
ErrorCorrectionLevelInternal m_EcLevelInternal = ErrorCorrectionLevelInternal.H;
QRCodeInternal qrCodeInternal = new QRCodeInternal();
// Step 1: Choose the mode (encoding).
Mode mode = EncoderInternal.chooseMode(content, encoding);
// Step 2: Append "bytes" into "dataBits" in appropriate encoding.
BitVector dataBits = new BitVector();
EncoderInternal.appendBytes(content, mode, dataBits, encoding);
// Step 3: Initialize QR code that can contain "dataBits".
int numInputBytes = dataBits.sizeInBytes();
EncoderInternal.initQRCode(numInputBytes, m_EcLevelInternal, mode, qrCodeInternal);
// Step 4: Build another bit vector that contains header and data.
BitVector headerAndDataBits = new BitVector();
// Step 4.5: Append ECI message if applicable
if (mode == Mode.BYTE && !QRCodeConstantVariable.DefaultEncoding.Equals(encoding))
{
CharacterSetECI eci = CharacterSetECI.getCharacterSetECIByName(encoding);
if (eci != null)
{
EncoderInternal.appendECI(eci, headerAndDataBits);
}
}
EncoderInternal.appendModeInfo(mode, headerAndDataBits);
int numLetters = mode.Equals(Mode.BYTE)?dataBits.sizeInBytes():content.Length;
EncoderInternal.appendLengthInfo(numLetters, qrCodeInternal.Version, mode, headerAndDataBits);
headerAndDataBits.appendBitVector(dataBits);
// Step 5: Terminate the bits properly.
EncoderInternal.terminateBits(qrCodeInternal.NumDataBytes, headerAndDataBits);
// Step 6: Interleave data bits with error correction code.
BitVector finalBits = new BitVector();
EncoderInternal.interleaveWithECBytes(headerAndDataBits, qrCodeInternal.NumTotalBytes, qrCodeInternal.NumDataBytes, qrCodeInternal.NumRSBlocks, finalBits);
if(option == 3)
{
return;
}
// Step 7: Choose the mask pattern and set to "QRCodeInternal".
ByteMatrix matrix = new ByteMatrix(qrCodeInternal.MatrixWidth, qrCodeInternal.MatrixWidth);
qrCodeInternal.MaskPattern = EncoderInternal.chooseMaskPattern(finalBits, qrCodeInternal.EcLevelInternal, qrCodeInternal.Version, matrix);
// Step 8. Build the matrix and set it to "QRCodeInternal".
MatrixUtil.buildMatrix(finalBits, qrCodeInternal.EcLevelInternal, qrCodeInternal.Version, qrCodeInternal.MaskPattern, matrix);
qrCodeInternal.Matrix = matrix;
}
开发者ID:fengdc,项目名称:QrCode.Net,代码行数:56,代码来源:EncodePTest.cs
示例18: 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[i, 6]))
{
matrix[i, 6] = bit;
}
// Vertical line.
if (isEmpty(matrix[6, i]))
{
matrix[6, i] = bit;
}
}
}
开发者ID:n1rvana,项目名称:ZXing.NET,代码行数:19,代码来源:MatrixUtil.cs
示例19: applyMaskPenaltyRule4
/// <summary>
/// Apply mask penalty rule 4 and return the penalty. Calculate the ratio of dark cells and give
/// penalty if the ratio is far from 50%. It gives 10 penalty for 5% distance.
/// </summary>
internal static int applyMaskPenaltyRule4(ByteMatrix matrix)
{
int numDarkCells = 0;
sbyte[][] array = matrix.Array;
int width = matrix.Width;
int height = matrix.Height;
for (int y = 0; y < height; y++)
{
sbyte[] arrayY = array[y];
for (int x = 0; x < width; x++)
{
if (arrayY[x] == 1)
{
numDarkCells++;
}
}
}
int numTotalCells = matrix.Height * matrix.Width;
double darkRatio = (double) numDarkCells / numTotalCells;
int fivePercentVariances = (int)(Math.Abs(darkRatio - 0.5) * 20.0); // * 100.0 / 5.0
return fivePercentVariances * N4;
}
开发者ID:Th3Ya0vi,项目名称:GameHouseUniverse,代码行数:26,代码来源:MaskUtil.cs
示例20: embedDarkDotAtLeftBottomCorner
/// <summary>
/// Embed the lonely dark dot at left bottom corner. JISX0510:2004 (p.46)
/// </summary>
/// <param name="matrix">The matrix.</param>
private static void embedDarkDotAtLeftBottomCorner(ByteMatrix matrix)
{
if (matrix[8, matrix.Height - 8] == 0)
{
throw new WriterException();
}
matrix[8, matrix.Height - 8] = 1;
}
开发者ID:n1rvana,项目名称:ZXing.NET,代码行数:12,代码来源:MatrixUtil.cs
注:本文中的ByteMatrix类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论