public virtual int distanceOf(Point other) { int x2 = other.X; int y2 = other.Y; return(QRCodeUtility.sqrt((x - x2) * (x - x2) + (y - y2) * (y - y2))); }
/// <summary> /// Encode the content using the encoding scheme given /// </summary> /// <param name="content"></param> /// <param name="encoding"></param> /// <returns></returns> public virtual Bitmap Encode(String content) { if (QRCodeUtility.IsUniCode(content)) { return(Encode(content, Encoding.Unicode)); } else { return(Encode(content, Encoding.ASCII)); } }
public virtual String decode(QRCodeImage qrCodeImage) { sbyte[] data = decodeBytes(qrCodeImage); byte[] byteData = new byte[data.Length]; Buffer.BlockCopy(data, 0, byteData, 0, byteData.Length); Encoding encoding; if (QRCodeUtility.IsUnicode(byteData)) { encoding = Encoding.Unicode; } else { encoding = Encoding.ASCII; } String decodedData; decodedData = encoding.GetString(byteData); return(decodedData); }
public virtual QRCodeSymbol getQRCodeSymbol(int[][] image) { int longSide = (image.Length < image[0].Length)?image[0].Length:image.Length; DECIMAL_POINT = 23 - QRCodeUtility.sqrt(longSide / 256); bitmap = filterImage(image); canvas.println("Drawing matrix."); canvas.drawMatrix(bitmap); canvas.println("Scanning Finder Pattern."); FinderPattern finderPattern = null; try { finderPattern = FinderPattern.findFinderPattern(bitmap); } catch (FinderPatternNotFoundException e) { canvas.println("Not found, now retrying..."); bitmap = applyCrossMaskingMedianFilter(bitmap, 5); canvas.drawMatrix(bitmap); for (int i = 0; i < 1000000000; i++) { ; } try { finderPattern = FinderPattern.findFinderPattern(bitmap); } catch (FinderPatternNotFoundException e2) { throw new SymbolNotFoundException(e2.Message); } catch (VersionInformationException e2) { throw new SymbolNotFoundException(e2.Message); } } catch (VersionInformationException e) { throw new SymbolNotFoundException(e.Message); } canvas.println("FinderPattern at"); String finderPatternCoordinates = finderPattern.getCenter(FinderPattern.UL).ToString() + finderPattern.getCenter(FinderPattern.UR).ToString() + finderPattern.getCenter(FinderPattern.DL).ToString(); canvas.println(finderPatternCoordinates); int[] sincos = finderPattern.getAngle(); canvas.println("Angle*4098: Sin " + System.Convert.ToString(sincos[0]) + " " + "Cos " + System.Convert.ToString(sincos[1])); int version = finderPattern.Version; canvas.println("Version: " + System.Convert.ToString(version)); if (version < 1 || version > 40) { throw new InvalidVersionException("Invalid version: " + version); } AlignmentPattern alignmentPattern = null; try { alignmentPattern = AlignmentPattern.findAlignmentPattern(bitmap, finderPattern); } catch (AlignmentPatternNotFoundException e) { throw new SymbolNotFoundException(e.Message); } int matrixLength = alignmentPattern.getCenter().Length; canvas.println("AlignmentPatterns at"); for (int y = 0; y < matrixLength; y++) { String alignmentPatternCoordinates = ""; for (int x = 0; x < matrixLength; x++) { alignmentPatternCoordinates += alignmentPattern.getCenter()[x][y].ToString(); } canvas.println(alignmentPatternCoordinates); } //for(int i = 0; i < 500000; i++) Console.out.println(""); canvas.println("Creating sampling grid."); //[TODO] need all-purpose method //samplingGrid = getSamplingGrid2_6(finderPattern, alignmentPattern); samplingGrid = getSamplingGrid(finderPattern, alignmentPattern); canvas.println("Reading grid."); bool[][] qRCodeMatrix = null; try { qRCodeMatrix = getQRCodeMatrix(bitmap, samplingGrid); } catch (System.IndexOutOfRangeException e) { throw new SymbolNotFoundException("Sampling grid exceeded image boundary"); } //canvas.drawMatrix(qRCodeMatrix); return(new QRCodeSymbol(qRCodeMatrix)); }
/// <summary> /// Encode the content using the encoding scheme given /// </summary> /// <param name="content"> /// </param> /// <returns> /// </returns> public virtual Bitmap Encode(string content) { return(this.Encode(content, QRCodeUtility.IsUniCode(content) ? Encoding.Unicode : Encoding.ASCII)); }