Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can i limit the reading area? #29

Open
primissus opened this issue Dec 15, 2016 · 5 comments
Open

Can i limit the reading area? #29

primissus opened this issue Dec 15, 2016 · 5 comments

Comments

@primissus
Copy link

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

@nisrulz
Copy link
Owner

nisrulz commented Dec 15, 2016

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.

@primissus
Copy link
Author

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.

@nisrulz
Copy link
Owner

nisrulz commented Jan 10, 2017

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

@simonkarmy
Copy link

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

@NilaxSpaceo
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants