zxing-android-embedded icon indicating copy to clipboard operation
zxing-android-embedded copied to clipboard

QR Code camera frame position

Open ranjeetchouhan opened this issue 5 years ago • 9 comments

I want to draw this camera position to top and wants to remaining layout as it is along with ResultPoints.

zxing

ranjeetchouhan avatar Dec 17 '19 11:12 ranjeetchouhan

This is not currently possible without modifying the library source code.

rkistner avatar Dec 18 '19 16:12 rkistner

Hi @rkistner i would like to know that that i am able to modify library source code after doing will make PR for merging but couldn't unable to get to where to modify source code in CameraPreview or ViewFinder or CameraManager or DecoratedBarCodeView etc.

ranjeetchouhan avatar Dec 19 '19 05:12 ranjeetchouhan

What you're looking for is setCropRect(). It is currently set here:

https://github.com/journeyapps/zxing-android-embedded/blob/9319110de8927fb4771b928eaf795e43999d8529/zxing-android-embedded/src/com/journeyapps/barcodescanner/BarcodeView.java#L179

So you can subclass BarcodeView and override getPreviewFramingRect(). The default implementation is here: https://github.com/journeyapps/zxing-android-embedded/blob/9319110de8927fb4771b928eaf795e43999d8529/zxing-android-embedded/src/com/journeyapps/barcodescanner/CameraPreview.java#L833-L853

rkistner avatar Dec 19 '19 09:12 rkistner

I override getPreviewFramingRect in BarcodeView and returning a fixed Rect @Override public Rect getPreviewFramingRect() { return new Rect(400,400,150,150); }

but still, preview frame still drawing at center and no difference in size

ranjeetchouhan avatar Dec 19 '19 10:12 ranjeetchouhan

My previous comment was slightly incorrect. Try overriding calculateFramingRect() instead.

rkistner avatar Dec 19 '19 10:12 rkistner

I tried with calculateFramingRect but didn't succeed. Can we connect over mail so i can send you logs and code segment as well

ranjeetchouhan avatar Dec 19 '19 10:12 ranjeetchouhan

This project is community-supported, so we can only provide support over GitHub issues for this.

rkistner avatar Dec 20 '19 09:12 rkistner

I wanted to change position of frame from center to top of barcodeview, so @rkistner comment help me a lot, and you can use it:

square frame: barcodeView.framingRectSize = Size(displayMetrics.widthPixels, displayMetrics.widthPixels) extend BarcodeView from zxing class TopRectBarcodeView @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 ) : BarcodeView(context, attrs, defStyleAttr) {}

and override calculateFramingRect override fun calculateFramingRect(container: Rect?, surface: Rect?): Rect { // intersection is the part of the container that is used for the preview val intersection = Rect(container) val intersects = intersection.intersect(surface) if (framingRectSize != null) { // Specific size is specified. Make sure it's not larger than the container or surface. intersection.top = 0 intersection.left = 0 intersection.right = framingRectSize.width intersection.bottom = framingRectSize.height return intersection } }

sry for code format:/

tsetserskaya avatar May 11 '20 23:05 tsetserskaya

https://medium.com/@mhmdawaddd/change-the-frame-position-and-size-of-the-zxing-barcode-scanning-library-for-android-95747919cfbe

hope this fit for anyone still searching

MhmdAwad avatar Sep 22 '22 12:09 MhmdAwad