qreader icon indicating copy to clipboard operation
qreader copied to clipboard

Can i limit the reading area?

Open primissus opened this issue 9 years ago • 5 comments

Is there any way I can use the full screen camera area to display but limit the reading area to a subview?

primissus avatar Dec 15 '16 17:12 primissus

Yes. The reading area is your SurfaceView, so how you size it (be it full screen or a specific height and width) in your layout is on you. Next is where you display your read data into , again depends on where you show the read data.

I may be able to answer more clearly if you gave me a specific case.

nisrulz avatar Dec 15 '16 18:12 nisrulz

Hi, I'm sorry I lated too much to answer but I've been a little busy. What I was trying to say is that I wanted to show the camera on the whole screen but limit the qr reading area to another inside view, like this:

rect3344

I ended up modifying your QRDataListener by adding another onDetected method that sends the whole Barcode object so i could get the Rect of the read data and compare it to the Rect of my inside view in order to limit the reading area.

QRDataListener:

public interface QRDataListener {

  /**
   * On detected.
   *
   * @param data
   *     the data
   */
  // Called from not main thread. Be careful
  void onDetected(final String data);


  // Allows to use the whole captured data
  void onDetected(final Barcode data);
}

QREader:

@Override
        public void receiveDetections(Detector.Detections<Barcode> detections) {
          final SparseArray<Barcode> barcodes = detections.getDetectedItems();
          if (barcodes.size() != 0 && qrDataListener != null) {
            qrDataListener.onDetected(barcodes.valueAt(0));
            qrDataListener.onDetected(barcodes.valueAt(0).displayValue);
          }
        }

My implementation:

...
qReader = new QREader.Builder(ScanActivity.this, scanner, new QRDataListener() {
            @Override
            public void onDetected(final String data) {
            }

            @Override
            public void onDetected(Barcode barcode) {
                if(areaRect.contains(barcode.getBoundingBox())) {
                    final String data = barcode.displayValue;
                    qReader.stop();
                    ...
                }
            }


        }).facing(QREader.BACK_CAM)
                .enableAutofocus(true)
                .height(width)
                .width(height)
                .build();
...

I hope this could help somebody else and I thank you for your attention.

primissus avatar Dec 31 '16 05:12 primissus

@primissus if you added a feature, do consider sending a PR.

nisrulz avatar Jan 10 '17 18:01 nisrulz

I am facing a problem on the aspect ratio of the camera preview. Always displayed with bad aspect ration. What to do ??

simonkarmy avatar Feb 16 '17 21:02 simonkarmy

@simonkarmy I am facing same issue too. did you get any solution for that?

NilaxSpaceo avatar Dec 26 '17 10:12 NilaxSpaceo