zxing-android-embedded
zxing-android-embedded copied to clipboard
QR Code camera frame position
I want to draw this camera position to top and wants to remaining layout as it is along with ResultPoints.

This is not currently possible without modifying the library source code.
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.
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
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
My previous comment was slightly incorrect. Try overriding calculateFramingRect()
instead.
I tried with calculateFramingRect but didn't succeed. Can we connect over mail so i can send you logs and code segment as well
This project is community-supported, so we can only provide support over GitHub issues for this.
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:/
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