Search in sources :

Example 71 with ResultPoint

use of com.google.zxing.ResultPoint in project zxingfragmentlib by mitoyarzun.

the class BarCodeScannerFragment method drawResultPoints.

/**
 * Superimpose a line for 1D or dots for 2D to highlight the key features of the barcode.
 *
 * @param barcode   A bitmap of the captured image.
 * @param scaleFactor amount by which thumbnail was scaled
 * @param rawResult The decoded results which contains the points to draw.
 */
private void drawResultPoints(Bitmap barcode, float scaleFactor, Result rawResult) {
    ResultPoint[] points = rawResult.getResultPoints();
    if (points != null && points.length > 0) {
        Canvas canvas = new Canvas(barcode);
        Paint paint = new Paint();
        paint.setColor(getResources().getColor(R.color.result_points));
        if (points.length == 2) {
            paint.setStrokeWidth(4.0f);
            drawLine(canvas, paint, points[0], points[1], scaleFactor);
        } else if (points.length == 4 && (rawResult.getBarcodeFormat() == BarcodeFormat.UPC_A || rawResult.getBarcodeFormat() == BarcodeFormat.EAN_13)) {
            // Hacky special case -- draw two lines, for the barcode and metadata
            drawLine(canvas, paint, points[0], points[1], scaleFactor);
            drawLine(canvas, paint, points[2], points[3], scaleFactor);
        } else {
            paint.setStrokeWidth(10.0f);
            for (ResultPoint point : points) {
                if (point != null) {
                    canvas.drawPoint(scaleFactor * point.getX(), scaleFactor * point.getY(), paint);
                }
            }
        }
    }
}
Also used : ResultPoint(com.google.zxing.ResultPoint) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint)

Example 72 with ResultPoint

use of com.google.zxing.ResultPoint in project zxingfragmentlib by mitoyarzun.

the class ViewfinderView method addPossibleResultPoint.

public void addPossibleResultPoint(ResultPoint point) {
    List<ResultPoint> points = possibleResultPoints;
    synchronized (points) {
        points.add(point);
        int size = points.size();
        if (size > MAX_RESULT_POINTS) {
            // trim it
            points.subList(0, size - MAX_RESULT_POINTS / 2).clear();
        }
    }
}
Also used : ResultPoint(com.google.zxing.ResultPoint) ResultPoint(com.google.zxing.ResultPoint) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint)

Example 73 with ResultPoint

use of com.google.zxing.ResultPoint in project zxingfragmentlib by mitoyarzun.

the class ViewfinderView method onDraw.

@SuppressLint("DrawAllocation")
@Override
public void onDraw(Canvas canvas) {
    if (cameraManager == null) {
        // not ready yet, early draw before done configuring
        return;
    }
    Rect frame = cameraManager.getFramingRect();
    Rect previewFrame = cameraManager.getFramingRectInPreview();
    if (frame == null || previewFrame == null) {
        return;
    }
    int width = canvas.getWidth();
    int height = canvas.getHeight();
    // Draw the exterior (i.e. outside the framing rect) darkened
    paint.setColor(resultBitmap != null ? resultColor : maskColor);
    canvas.drawRect(0, 0, width, frame.top, paint);
    canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, paint);
    canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1, paint);
    canvas.drawRect(0, frame.bottom + 1, width, height, paint);
    if (resultBitmap != null) {
        // Draw the opaque result bitmap over the scanning rectangle
        paint.setAlpha(CURRENT_POINT_OPACITY);
        canvas.drawBitmap(resultBitmap, null, frame, paint);
    } else {
        // Draw a red "laser scanner" line through the middle to show decoding is active
        paint.setColor(laserColor);
        paint.setAlpha(SCANNER_ALPHA[scannerAlpha]);
        scannerAlpha = (scannerAlpha + 1) % SCANNER_ALPHA.length;
        int middle = frame.height() / 2 + frame.top;
        canvas.drawRect(frame.left + 2, middle - 1, frame.right - 1, middle + 2, paint);
        float scaleX = frame.width() / (float) previewFrame.width();
        float scaleY = frame.height() / (float) previewFrame.height();
        List<ResultPoint> currentPossible = possibleResultPoints;
        List<ResultPoint> currentLast = lastPossibleResultPoints;
        int frameLeft = frame.left;
        int frameTop = frame.top;
        if (currentPossible.isEmpty()) {
            lastPossibleResultPoints = null;
        } else {
            possibleResultPoints = new ArrayList<>(5);
            lastPossibleResultPoints = currentPossible;
            paint.setAlpha(CURRENT_POINT_OPACITY);
            paint.setColor(resultPointColor);
            synchronized (currentPossible) {
                for (ResultPoint point : currentPossible) {
                    canvas.drawCircle(frameLeft + (int) (point.getX() * scaleX), frameTop + (int) (point.getY() * scaleY), POINT_SIZE, paint);
                }
            }
        }
        if (currentLast != null) {
            paint.setAlpha(CURRENT_POINT_OPACITY / 2);
            paint.setColor(resultPointColor);
            synchronized (currentLast) {
                float radius = POINT_SIZE / 2.0f;
                for (ResultPoint point : currentLast) {
                    canvas.drawCircle(frameLeft + (int) (point.getX() * scaleX), frameTop + (int) (point.getY() * scaleY), radius, paint);
                }
            }
        }
        // Request another update at the animation interval, but only repaint the laser line,
        // not the entire viewfinder mask.
        postInvalidateDelayed(ANIMATION_DELAY, frame.left - POINT_SIZE, frame.top - POINT_SIZE, frame.right + POINT_SIZE, frame.bottom + POINT_SIZE);
    }
}
Also used : Rect(android.graphics.Rect) ResultPoint(com.google.zxing.ResultPoint) ResultPoint(com.google.zxing.ResultPoint) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint)

Example 74 with ResultPoint

use of com.google.zxing.ResultPoint in project react-native-camera by lwansbrough.

the class BarCodeReadEvent method serializeEventData.

private WritableMap serializeEventData() {
    WritableMap event = Arguments.createMap();
    WritableMap eventOrigin = Arguments.createMap();
    event.putInt("target", getViewTag());
    event.putString("data", mBarCode.getText());
    byte[] rawBytes = mBarCode.getRawBytes();
    if (rawBytes != null && rawBytes.length > 0) {
        Formatter formatter = new Formatter();
        for (byte b : rawBytes) {
            formatter.format("%02x", b);
        }
        event.putString("rawData", formatter.toString());
        formatter.close();
    }
    event.putString("type", mBarCode.getBarcodeFormat().toString());
    WritableArray resultPoints = Arguments.createArray();
    ResultPoint[] points = mBarCode.getResultPoints();
    for (ResultPoint point : points) {
        if (point != null) {
            WritableMap newPoint = Arguments.createMap();
            newPoint.putString("x", String.valueOf(point.getX()));
            newPoint.putString("y", String.valueOf(point.getY()));
            resultPoints.pushMap(newPoint);
        }
    }
    eventOrigin.putArray("origin", resultPoints);
    eventOrigin.putInt("height", mHeight);
    eventOrigin.putInt("width", mWidth);
    event.putMap("bounds", eventOrigin);
    if (mCompressedImage != null) {
        event.putString("image", Base64.encodeToString(mCompressedImage, Base64.NO_WRAP));
    }
    return event;
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap) ResultPoint(com.google.zxing.ResultPoint) WritableArray(com.facebook.react.bridge.WritableArray) Formatter(java.util.Formatter)

Example 75 with ResultPoint

use of com.google.zxing.ResultPoint in project smartmodule by carozhu.

the class ViewfinderView method addPossibleResultPoint.

public void addPossibleResultPoint(ResultPoint point) {
    List<ResultPoint> points = possibleResultPoints;
    synchronized (points) {
        points.add(point);
        int size = points.size();
        if (size > MAX_RESULT_POINTS) {
            // trim it
            points.subList(0, size - MAX_RESULT_POINTS / 2).clear();
        }
    }
}
Also used : ResultPoint(com.google.zxing.ResultPoint) ResultPoint(com.google.zxing.ResultPoint) Paint(android.graphics.Paint)

Aggregations

ResultPoint (com.google.zxing.ResultPoint)252 Result (com.google.zxing.Result)77 Paint (android.graphics.Paint)45 Rect (android.graphics.Rect)24 BitMatrix (com.google.zxing.common.BitMatrix)22 DecoderResult (com.google.zxing.common.DecoderResult)22 NotFoundException (com.google.zxing.NotFoundException)21 DetectorResult (com.google.zxing.common.DetectorResult)20 ArrayList (java.util.ArrayList)20 ReaderException (com.google.zxing.ReaderException)16 SuppressLint (android.annotation.SuppressLint)13 ResultPointCallback (com.google.zxing.ResultPointCallback)12 Canvas (android.graphics.Canvas)10 ResultMetadataType (com.google.zxing.ResultMetadataType)8 BitArray (com.google.zxing.common.BitArray)8 QRCodeDecoderMetaData (com.google.zxing.qrcode.decoder.QRCodeDecoderMetaData)8 BarcodeFormat (com.google.zxing.BarcodeFormat)5 FormatException (com.google.zxing.FormatException)4 Decoder (com.google.zxing.aztec.decoder.Decoder)4 Detector (com.google.zxing.aztec.detector.Detector)4