Ejemplo n.º 1
0
        public virtual sbyte[] get8bitByteArray(int dataLength)
        {
            int length  = dataLength;
            int intData = 0;

            System.IO.MemoryStream output = new System.IO.MemoryStream();

            do
            {
                canvas.println("Length: " + length);
                intData = getNextBits(8);
                output.WriteByte((byte)intData);
                length--;
            }while (length > 0);
            return(SystemUtils.ToSByteArray(output.ToArray()));
        }
Ejemplo n.º 2
0
        /*	public byte[] decode(QRCodeImage qrCodeImage) throws DecodingFailedException{
         *  canvas.println("Decoding started.");
         *  int[][] intImage = imageToIntArray(qrCodeImage);
         *  try {
         *  QRCodeImageReader reader = new QRCodeImageReader();
         *  qrCodeSymbol = reader.getQRCodeSymbol(intImage);
         *  } catch (SymbolNotFoundException e) {
         *  throw new DecodingFailedException(e.getMessage());
         *  }
         *  canvas.println("Created QRCode symbol.");
         *  canvas.println("Reading symbol.");
         *  canvas.println("Version: " + qrCodeSymbol.getVersionReference());
         *  canvas.println("Mask pattern: " + qrCodeSymbol.getMaskPatternRefererAsString());
         *  int[] blocks = qrCodeSymbol.getBlocks();
         *  canvas.println("Correcting data errors.");
         *  int[] dataBlocks = correctDataBlocks(blocks);
         *  try {
         *  byte[] decodedByteArray =
         *  getDecodedByteArray(dataBlocks, qrCodeSymbol.getVersion());
         *  canvas.println("Decoding finished.");
         *  return decodedByteArray;
         *  } catch (InvalidDataBlockException e) {
         *  throw new DecodingFailedException(e.getMessage());
         *  }
         * }*/

        public virtual sbyte[] decodeBytes(QRCodeImage qrCodeImage)
        {
            Point[] adjusts = AdjustPoints;
            System.Collections.ArrayList results = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
            while (numTryDecode < adjusts.Length)
            {
                try
                {
                    DecodeResult result = decode(qrCodeImage, adjusts[numTryDecode]);
                    if (result.CorrectionSucceeded)
                    {
                        return(result.DecodedBytes);
                    }
                    else
                    {
                        results.Add(result);
                        canvas.println("Decoding succeeded but could not correct");
                        canvas.println("all errors. Retrying..");
                    }
                }
                catch (DecodingFailedException dfe)
                {
                    if (dfe.Message.IndexOf("Finder Pattern") >= 0)
                    {
                        throw dfe;
                    }
                }
                finally
                {
                    numTryDecode += 1;
                }
            }

            if (results.Count == 0)
            {
                throw new DecodingFailedException("Give up decoding");
            }

            int lowestErrorIndex = -1;
            int lowestError      = System.Int32.MaxValue;

            for (int i = 0; i < results.Count; i++)
            {
                DecodeResult result = (DecodeResult)results[i];
                if (result.NumErrors < lowestError)
                {
                    lowestError      = result.NumErrors;
                    lowestErrorIndex = i;
                }
            }
            canvas.println("All trials need for correct error");
            canvas.println("Reporting #" + (lowestErrorIndex) + " that,");
            canvas.println("corrected minimum errors (" + lowestError + ")");

            canvas.println("Decoding finished.");
            return(((DecodeResult)results[lowestErrorIndex]).DecodedBytes);
        }