当前位置: 首页>>代码示例>>C#>>正文


C# ByteMatrix类代码示例

本文整理汇总了C#中ByteMatrix的典型用法代码示例。如果您正苦于以下问题:C# ByteMatrix类的具体用法?C# ByteMatrix怎么用?C# ByteMatrix使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ByteMatrix类属于命名空间,在下文中一共展示了ByteMatrix类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的ByteMatrix类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。