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


C# Common.BitArray类代码示例

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


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

示例1: buildBitArrayFromString

      /// <summary>
      /// Constructs a BitArray from a String like the one returned from BitArray.toString()
      /// </summary>
      public static BitArray buildBitArrayFromString(String data)
      {
         String dotsAndXs = Regex.Replace(Regex.Replace(data, ONE, "X"), ZERO, ".");
         BitArray binary = new BitArray(Regex.Replace(dotsAndXs, SPACE, "").Length);
         int counter = 0;

         for (int i = 0; i < dotsAndXs.Length; ++i)
         {
            if (i % 9 == 0)
            { // spaces
               if (dotsAndXs[i] != ' ')
               {
                  throw new InvalidOperationException("space expected");
               }
               continue;
            }

            char currentChar = dotsAndXs[i];
            if (currentChar == 'X' || currentChar == 'x')
            {
               binary[counter] = true;
            }
            counter++;
         }
         return binary;
      }
开发者ID:n1rvana,项目名称:ZXing.NET,代码行数:29,代码来源:BinaryUtil.cs

示例2: decodeMiddle

      /// <summary>
      /// Decodes the middle.
      /// </summary>
      /// <param name="row">The row.</param>
      /// <param name="startRange">The start range.</param>
      /// <param name="result">The result.</param>
      /// <returns></returns>
      override internal protected int decodeMiddle(BitArray row, int[] startRange, StringBuilder result)
      {
         int[] counters = decodeMiddleCounters;
         counters[0] = 0;
         counters[1] = 0;
         counters[2] = 0;
         counters[3] = 0;
         int end = row.Size;
         int rowOffset = startRange[1];

         int lgPatternFound = 0;

         for (int x = 0; x < 6 && rowOffset < end; x++)
         {
            int bestMatch;
            if (!decodeDigit(row, counters, rowOffset, L_AND_G_PATTERNS, out bestMatch))
               return -1;
            result.Append((char)('0' + bestMatch % 10));
            foreach (int counter in counters)
            {
               rowOffset += counter;
            }
            if (bestMatch >= 10)
            {
               lgPatternFound |= 1 << (5 - x);
            }
         }

         if (!determineNumSysAndCheckDigit(result, lgPatternFound))
            return -1;

         return rowOffset;
      }
开发者ID:Bogdan-p,项目名称:ZXing.Net,代码行数:40,代码来源:UPCEReader.cs

示例3: appendTo

 public override void appendTo(BitArray bitArray, byte[] text)
 {
    for (int i = 0; i < binaryShiftByteCount; i++)
    {
       if (i == 0 || (i == 31 && binaryShiftByteCount <= 62))
       {
          // We need a header before the first character, and before
          // character 31 when the total byte code is <= 62
          bitArray.appendBits(31, 5);  // BINARY_SHIFT
          if (binaryShiftByteCount > 62)
          {
             bitArray.appendBits(binaryShiftByteCount - 31, 16);
          }
          else if (i == 0)
          {
             // 1 <= binaryShiftByteCode <= 62
             bitArray.appendBits(Math.Min(binaryShiftByteCount, (short) 31), 5);
          }
          else
          {
             // 32 <= binaryShiftCount <= 62 and i == 31
             bitArray.appendBits(binaryShiftByteCount - 31, 5);
          }
       }
       bitArray.appendBits(text[binaryShiftStart + i], 8);
    }
 }
开发者ID:n1rvana,项目名称:ZXing.NET,代码行数:27,代码来源:BinaryShiftToken.cs

示例4: decodeRow

      internal Result decodeRow(int rowNumber, BitArray row, int[] extensionStartRange)
      {
         StringBuilder result = decodeRowStringBuffer;
         result.Length = 0;
         int end = decodeMiddle(row, extensionStartRange, result);
         if (end < 0)
            return null;

         String resultString = result.ToString();
         IDictionary<ResultMetadataType, Object> extensionData = parseExtensionString(resultString);

         Result extensionResult =
             new Result(resultString,
                        null,
                        new ResultPoint[] {
                       new ResultPoint((extensionStartRange[0] + extensionStartRange[1]) / 2.0f, (float) rowNumber),
                       new ResultPoint((float) end, (float) rowNumber),
                   },
                        BarcodeFormat.UPC_EAN_EXTENSION);
         if (extensionData != null)
         {
            extensionResult.putAllMetadata(extensionData);
         }
         return extensionResult;
      }
开发者ID:hydrayu,项目名称:imobile-src,代码行数:25,代码来源:UPCEANExtension2Support.cs

示例5: decodeRow

 /// <summary>
 ///   <p>Attempts to decode a one-dimensional barcode format given a single row of
 /// an image.</p>
 /// </summary>
 /// <param name="rowNumber">row number from top of the row</param>
 /// <param name="row">the black/white pixel data of the row</param>
 /// <param name="hints">decode hints</param>
 /// <returns>
 ///   <see cref="Result"/>containing encoded string and start/end of barcode or null, if an error occurs or barcode cannot be found
 /// </returns>
 override public Result decodeRow(int rowNumber,
                         BitArray row,
                         IDictionary<DecodeHintType, object> hints)
 {
    Pair leftPair = decodePair(row, false, rowNumber, hints);
    addOrTally(possibleLeftPairs, leftPair);
    row.reverse();
    Pair rightPair = decodePair(row, true, rowNumber, hints);
    addOrTally(possibleRightPairs, rightPair);
    row.reverse();
    int lefSize = possibleLeftPairs.Count;
    for (int i = 0; i < lefSize; i++)
    {
       Pair left = possibleLeftPairs[i];
       if (left.Count > 1)
       {
          int rightSize = possibleRightPairs.Count;
          for (int j = 0; j < rightSize; j++)
          {
             Pair right = possibleRightPairs[j];
             if (right.Count > 1)
             {
                if (checkChecksum(left, right))
                {
                   return constructResult(left, right);
                }
             }
          }
       }
    }
    return null;
 }
开发者ID:arumata,项目名称:zxingnet,代码行数:42,代码来源:RSS14Reader.cs

示例6: decodeRow

 /// <summary>
 ///   <p>Attempts to decode a one-dimensional barcode format given a single row of
 /// an image.</p>
 /// </summary>
 /// <param name="rowNumber">row number from top of the row</param>
 /// <param name="row">the black/white pixel data of the row</param>
 /// <param name="hints">decode hints</param>
 /// <returns>
 ///   <see cref="Result"/>containing encoded string and start/end of barcode or null, if an error occurs or barcode cannot be found
 /// </returns>
 override public Result decodeRow(int rowNumber,
                         BitArray row,
                         IDictionary<DecodeHintType, object> hints)
 {
    Pair leftPair = decodePair(row, false, rowNumber, hints);
    addOrTally(possibleLeftPairs, leftPair);
    row.reverse();
    Pair rightPair = decodePair(row, true, rowNumber, hints);
    addOrTally(possibleRightPairs, rightPair);
    row.reverse();
    foreach (Pair left in possibleLeftPairs)
    {
       if (left.Count > 1)
       {
          foreach (Pair right in possibleRightPairs)
          {
             if (right.Count > 1)
             {
                if (checkChecksum(left, right))
                {
                   return constructResult(left, right);
                }
             }
          }
       }
    }
    return null;
 }
开发者ID:GSerjo,项目名称:Seminars,代码行数:38,代码来源:RSS14Reader.cs

示例7: decodeRow

 /// <summary>
 ///   <p>Like decodeRow(int, BitArray, java.util.Map), but
 /// allows caller to inform method about where the UPC/EAN start pattern is
 /// found. This allows this to be computed once and reused across many implementations.</p>
 /// </summary>
 /// <param name="rowNumber"></param>
 /// <param name="row"></param>
 /// <param name="startGuardRange"></param>
 /// <param name="hints"></param>
 /// <returns></returns>
 override public Result decodeRow(int rowNumber,
                         BitArray row,
                         int[] startGuardRange,
                         IDictionary<DecodeHintType, object> hints)
 {
    return maybeReturnResult(ean13Reader.decodeRow(rowNumber, row, startGuardRange, hints));
 }
开发者ID:sfurlani,项目名称:ZXing.Net.Mobile,代码行数:17,代码来源:UPCAReader.cs

示例8: Mirror

 /// <summary>
 /// Copies the bits from the input to the result BitArray in reverse order.
 /// SF: Not sure how this is different than BitArray.Reverse();
 /// </summary>
 /// <param name="input">Input.</param>
 /// <param name="result">Result.</param>
 private static void Mirror(BitArray input, ref BitArray result)
 {
     result.clear();
     int size = input.Size;
     for (int i = 0; i < size; i++)
     {
         result[size - 1 - i] = input[i];
     }
 }
开发者ID:Th3Ya0vi,项目名称:GameHouseUniverse,代码行数:15,代码来源:BitMatrixExtensions.cs

示例9: decodeRow

 internal Result decodeRow(int rowNumber, BitArray row, int rowOffset)
 {
    int[] extensionStartRange = UPCEANReader.findGuardPattern(row, rowOffset, false, EXTENSION_START_PATTERN);
    if (extensionStartRange == null)
       return null;
    var result = fiveSupport.decodeRow(rowNumber, row, extensionStartRange);
    if (result == null)
       result = twoSupport.decodeRow(rowNumber, row, extensionStartRange);
    return result;
 }
开发者ID:Bogdan-p,项目名称:ZXing.Net,代码行数:10,代码来源:UPCEANExtensionSupport.cs

示例10: getUnsignedInt

 private static long getUnsignedInt(BitArray v, int index)
 {
    long result = 0L;
    for (int i = 0, offset = index << 3; i < 32; i++)
    {
       if (v[offset + i])
       {
          result |= 1L << (31 - i);
       }
    }
    return result;
 }
开发者ID:n1rvana,项目名称:ZXing.NET,代码行数:12,代码来源:BitVectorTestCase.cs

示例11: buildBitArray

      internal static BitArray buildBitArray(List<ExpandedPair> pairs)
      {
         int charNumber = (pairs.Count << 1) - 1;
         if (pairs[pairs.Count - 1].RightChar == null)
         {
            charNumber -= 1;
         }

         int size = 12 * charNumber;

         BitArray binary = new BitArray(size);
         int accPos = 0;

         ExpandedPair firstPair = pairs[0];
         int firstValue = firstPair.RightChar.Value;
         for (int i = 11; i >= 0; --i)
         {
            if ((firstValue & (1 << i)) != 0)
            {
               binary[accPos] = true;
            }
            accPos++;
         }

         for (int i = 1; i < pairs.Count; ++i)
         {
            ExpandedPair currentPair = pairs[i];

            int leftValue = currentPair.LeftChar.Value;
            for (int j = 11; j >= 0; --j)
            {
               if ((leftValue & (1 << j)) != 0)
               {
                  binary[accPos] = true;
               }
               accPos++;
            }

            if (currentPair.RightChar != null)
            {
               int rightValue = currentPair.RightChar.Value;
               for (int j = 11; j >= 0; --j)
               {
                  if ((rightValue & (1 << j)) != 0)
                  {
                     binary[accPos] = true;
                  }
                  accPos++;
               }
            }
         }
         return binary;
      }
开发者ID:Binjaaa,项目名称:ZXing.Net.Mobile,代码行数:53,代码来源:BitArrayBuilder.cs

示例12: decodeMiddle

      /// <summary>
      /// Subclasses override this to decode the portion of a barcode between the start
      /// and end guard patterns.
      /// </summary>
      /// <param name="row">row of black/white values to search</param>
      /// <param name="startRange">start/end offset of start guard pattern</param>
      /// <param name="resultString"><see cref="StringBuilder"/>to append decoded chars to</param>
      /// <returns>
      /// horizontal offset of first pixel after the "middle" that was decoded or -1 if decoding could not complete successfully
      /// </returns>
      override protected internal int decodeMiddle(BitArray row,
                                 int[] startRange,
                                 StringBuilder resultString)
      {
         int[] counters = decodeMiddleCounters;
         counters[0] = 0;
         counters[1] = 0;
         counters[2] = 0;
         counters[3] = 0;
         int end = row.Size;
         int rowOffset = startRange[1];

         int lgPatternFound = 0;

         for (int x = 0; x < 6 && rowOffset < end; x++)
         {
            int bestMatch;
            if (!decodeDigit(row, counters, rowOffset, L_AND_G_PATTERNS, out bestMatch))
               return -1;
            resultString.Append((char) ('0' + bestMatch%10));
            foreach (int counter in counters)
            {
               rowOffset += counter;
            }
            if (bestMatch >= 10)
            {
               lgPatternFound |= 1 << (5 - x);
            }
         }

         if (!determineFirstDigit(resultString, lgPatternFound))
            return -1;

         int[] middleRange = findGuardPattern(row, rowOffset, true, MIDDLE_PATTERN);
         if (middleRange == null)
            return -1;
         rowOffset = middleRange[1];

         for (int x = 0; x < 6 && rowOffset < end; x++)
         {
            int bestMatch;
            if (!decodeDigit(row, counters, rowOffset, L_PATTERNS, out bestMatch))
               return -1;
            resultString.Append((char) ('0' + bestMatch));
            foreach (int counter in counters)
            {
               rowOffset += counter;
            }
         }

         return rowOffset;
      }
开发者ID:n1rvana,项目名称:ZXing.NET,代码行数:62,代码来源:EAN13Reader.cs

示例13: decodeMiddle

      int decodeMiddle(BitArray row, int[] startRange, StringBuilder resultString)
      {
         int[] counters = decodeMiddleCounters;
         counters[0] = 0;
         counters[1] = 0;
         counters[2] = 0;
         counters[3] = 0;
         int end = row.Size;
         int rowOffset = startRange[1];

         int lgPatternFound = 0;

         for (int x = 0; x < 5 && rowOffset < end; x++)
         {
            int bestMatch;
            if (!UPCEANReader.decodeDigit(row, counters, rowOffset, UPCEANReader.L_AND_G_PATTERNS, out bestMatch))
               return -1;
            resultString.Append((char)('0' + bestMatch % 10));
            foreach (int counter in counters)
            {
               rowOffset += counter;
            }
            if (bestMatch >= 10)
            {
               lgPatternFound |= 1 << (4 - x);
            }
            if (x != 4)
            {
               // Read off separator if not last
               rowOffset = row.getNextSet(rowOffset);
               rowOffset = row.getNextUnset(rowOffset);
            }
         }

         if (resultString.Length != 5)
         {
            return -1;
         }

         int checkDigit;
         if (!determineCheckDigit(lgPatternFound, out checkDigit))
            return -1;

         if (extensionChecksum(resultString.ToString()) != checkDigit)
         {
            return -1;
         }

         return rowOffset;
      }
开发者ID:Bogdan-p,项目名称:ZXing.Net,代码行数:50,代码来源:UPCEANExtension5Support.cs

示例14: decodeRow

      /// <summary>
      ///   <p>Attempts to decode a one-dimensional barcode format given a single row of
      /// an image.</p>
      /// </summary>
      /// <param name="rowNumber">row number from top of the row</param>
      /// <param name="row">the black/white pixel data of the row</param>
      /// <param name="hints">decode hints</param>
      /// <returns>
      ///   <see cref="Result"/>containing encoded string and start/end of barcode or null if an error occurs or barcode cannot be found
      /// </returns>
      override public Result decodeRow(int rowNumber,
                              BitArray row,
                              IDictionary<DecodeHintType, object> hints)
      {
         // Compute this location once and reuse it on multiple implementations
         int[] startGuardPattern = UPCEANReader.findStartGuardPattern(row);
         if (startGuardPattern == null)
            return null;

         foreach (UPCEANReader reader in readers)
         {
            Result result = reader.decodeRow(rowNumber, row, startGuardPattern, hints);
            if (result == null)
               continue;

            // Special case: a 12-digit code encoded in UPC-A is identical to a "0"
            // followed by those 12 digits encoded as EAN-13. Each will recognize such a code,
            // UPC-A as a 12-digit string and EAN-13 as a 13-digit string starting with "0".
            // Individually these are correct and their readers will both read such a code
            // and correctly call it EAN-13, or UPC-A, respectively.
            //
            // In this case, if we've been looking for both types, we'd like to call it
            // a UPC-A code. But for efficiency we only run the EAN-13 decoder to also read
            // UPC-A. So we special case it here, and convert an EAN-13 result to a UPC-A
            // result if appropriate.
            //
            // But, don't return UPC-A if UPC-A was not a requested format!
            bool ean13MayBeUPCA =
                result.BarcodeFormat == BarcodeFormat.EAN_13 &&
                    result.Text[0] == '0';
            var possibleFormats =
                hints == null || !hints.ContainsKey(DecodeHintType.POSSIBLE_FORMATS) ? null : (IList<BarcodeFormat>)hints[DecodeHintType.POSSIBLE_FORMATS];
            bool canReturnUPCA = possibleFormats == null || possibleFormats.Contains(BarcodeFormat.UPC_A) || possibleFormats.Contains(BarcodeFormat.All_1D);

            if (ean13MayBeUPCA && canReturnUPCA)
            {
               // Transfer the metdata across
               var resultUPCA = new Result(result.Text.Substring(1),
                                              result.RawBytes,
                                              result.ResultPoints,
                                              BarcodeFormat.UPC_A);
               resultUPCA.putAllMetadata(result.ResultMetadata);
               return resultUPCA;
            }
            return result;
         }

         return null;
      }
开发者ID:Bogdan-p,项目名称:ZXing.Net,代码行数:59,代码来源:MultiFormatUPCEANReader.cs

示例15: decodeMiddle

      int decodeMiddle(BitArray row, int[] startRange, StringBuilder resultString)
      {
         int[] counters = decodeMiddleCounters;
         counters[0] = 0;
         counters[1] = 0;
         counters[2] = 0;
         counters[3] = 0;
         int end = row.Size;
         int rowOffset = startRange[1];

         int checkParity = 0;

         for (int x = 0; x < 2 && rowOffset < end; x++)
         {
            int bestMatch;
            if (!UPCEANReader.decodeDigit(row, counters, rowOffset, UPCEANReader.L_AND_G_PATTERNS, out bestMatch))
               return -1;
            resultString.Append((char)('0' + bestMatch % 10));
            foreach (int counter in counters)
            {
               rowOffset += counter;
            }
            if (bestMatch >= 10)
            {
               checkParity |= 1 << (1 - x);
            }
            if (x != 1)
            {
               // Read off separator if not last
               rowOffset = row.getNextSet(rowOffset);
               rowOffset = row.getNextUnset(rowOffset);
            }
         }

         if (resultString.Length != 2)
         {
            return -1;
         }

         if (int.Parse(resultString.ToString()) % 4 != checkParity)
         {
            return -1;
         }

         return rowOffset;
      }
开发者ID:hydrayu,项目名称:imobile-src,代码行数:46,代码来源:UPCEANExtension2Support.cs


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