Search in sources :

Example 6 with Point

use of jp.sourceforge.qrcode.geom.Point in project qrcode by yanbe.

the class JMFCanvas method drawPolygon.

public void drawPolygon(Point[] points, int color) {
    Graphics2D g2d = image.createGraphics();
    g2d.setColor(new Color(color));
    int numPoints = points.length;
    int[] polygonX = new int[numPoints];
    int[] polygonY = new int[numPoints];
    for (int i = 0; i < numPoints; i++) {
        polygonX[i] = points[i].getX();
        polygonY[i] = points[i].getY();
    }
    g2d.drawPolygon(polygonX, polygonY, numPoints);
    repaint();
}
Also used : Color(java.awt.Color) Point(jp.sourceforge.qrcode.geom.Point) Graphics2D(java.awt.Graphics2D)

Example 7 with Point

use of jp.sourceforge.qrcode.geom.Point in project qrcode by yanbe.

the class JMFCanvas method drawCross.

public void drawCross(Point point, int color) {
    int x = point.getX();
    int y = point.getY();
    Line[] lines = { new Line(x - 5, y - 1, x + 5, y - 1), new Line(x - 1, y - 5, x - 1, y + 5), new Line(x - 5, y + 1, x + 5, y + 1), new Line(x + 1, y - 5, x + 1, y + 5), new Line(x - 5, y, x + 5, y), new Line(x, y - 5, x, y + 5) };
    drawLines(lines, color);
}
Also used : Line(jp.sourceforge.qrcode.geom.Line) Point(jp.sourceforge.qrcode.geom.Point)

Example 8 with Point

use of jp.sourceforge.qrcode.geom.Point in project qrcode by yanbe.

the class JMFCanvas method drawPoints.

public void drawPoints(Point[] points, int color) {
    Graphics2D g2d = image.createGraphics();
    g2d.setColor(new Color(color));
    for (int i = 0; i < points.length; i++) g2d.drawLine(points[i].getX(), points[i].getY(), points[i].getX(), points[i].getY());
    repaint();
}
Also used : Color(java.awt.Color) Point(jp.sourceforge.qrcode.geom.Point) Graphics2D(java.awt.Graphics2D)

Example 9 with Point

use of jp.sourceforge.qrcode.geom.Point in project qrcode by yanbe.

the class QRCodeDecoder method decode.

public byte[] decode(QRCodeImage qrCodeImage) throws DecodingFailedException {
    Point[] adjusts = getAdjustPoints();
    Vector results = new Vector();
    numTryDecode = 0;
    while (numTryDecode < adjusts.length) {
        try {
            DecodeResult result = decode(qrCodeImage, adjusts[numTryDecode]);
            if (result.isCorrectionSucceeded()) {
                return result.getDecodedBytes();
            } else {
                results.addElement(result);
                canvas.println("Decoding succeeded but could not correct");
                canvas.println("all errors. Retrying..");
            }
        } catch (DecodingFailedException dfe) {
            if (dfe.getMessage().indexOf("Finder Pattern") >= 0)
                throw dfe;
        } finally {
            numTryDecode += 1;
        }
    }
    if (results.size() == 0)
        throw new DecodingFailedException("Give up decoding");
    int minErrorIndex = -1;
    int minError = Integer.MAX_VALUE;
    for (int i = 0; i < results.size(); i++) {
        DecodeResult result = (DecodeResult) results.elementAt(i);
        if (result.getNumCorrectuionFailures() < minError) {
            minError = result.getNumCorrectuionFailures();
            minErrorIndex = i;
        }
    }
    canvas.println("All trials need for correct error");
    canvas.println("Reporting #" + (minErrorIndex) + " that,");
    canvas.println("corrected minimum errors (" + minError + ")");
    canvas.println("Decoding finished.");
    return ((DecodeResult) results.elementAt(minErrorIndex)).getDecodedBytes();
}
Also used : Point(jp.sourceforge.qrcode.geom.Point) Vector(java.util.Vector) Point(jp.sourceforge.qrcode.geom.Point) DecodingFailedException(jp.sourceforge.qrcode.exception.DecodingFailedException)

Example 10 with Point

use of jp.sourceforge.qrcode.geom.Point in project qrcode by yanbe.

the class J2SEDebugCanvas method drawCross.

public void drawCross(Point point, int color) {
    int x = point.getX();
    int y = point.getY();
    Line[] lines = { new Line(x - 5, y, x + 5, y), new Line(x, y - 5, x, y + 5) };
    drawLines(lines, color);
}
Also used : Line(jp.sourceforge.qrcode.geom.Line) Point(jp.sourceforge.qrcode.geom.Point)

Aggregations

Point (jp.sourceforge.qrcode.geom.Point)10 Color (java.awt.Color)4 Graphics2D (java.awt.Graphics2D)4 Vector (java.util.Vector)2 Graphics (javax.microedition.lcdui.Graphics)2 Image (javax.microedition.lcdui.Image)2 QRCodeImage (jp.sourceforge.qrcode.data.QRCodeImage)2 Line (jp.sourceforge.qrcode.geom.Line)2 DecodingFailedException (jp.sourceforge.qrcode.exception.DecodingFailedException)1