Zxing is a QR code scanning project provided by google.
The default scan area of the Demo itself is only 360*480, which requires a long distance to scan the entire QR code.
Therefore, we need to adjust the image size ourselves.
Make adjustments in the CameraManager. java class.
The default size is the following four parameters.
// private static final int MIN_FRAME_WIDTH = 240;// private static final int MIN_FRAME_HEIGHT = 240;// private static final int MAX_FRAME_WIDTH = 480;// private static final int MAX_FRAME_HEIGHT = 360;
You can increase the value according to the screen size: Minimum width and height; maximum width and height.
The parameter actually plays a role in the getFramingRect () method.
The following are provided in the original Demo:
/*** Calculates the framing rect which the UI shocould draw to show the user where to place the * barcode. this target helps with alignment as well as forces the user to hold the device * far enough away to ensure the image will be in focus. ** @ return The rectangle to draw on screen in window coordinates. */public Rect getFramingRect () {Point screenResolution = configManager. getScreenResolution (); if (framingRect = null) {if (camera = null) {return null;} // native int width = screenResolution. x * 3/4; if (width <MIN_FRAME_WIDTH) {width = MIN_FRAME_WIDTH;} else if (width> MAX_FRAME_WIDTH) {width = MAX_FRAME_WIDTH;} int height = screenResolution. y * 3/4; if (height <MIN_FRAME_HEIGHT) {height = MIN_FRAME_HEIGHT;} else if (height> MAX_FRAME_HEIGHT) {height = MAX_FRAME_HEIGHT;} int leftOffset = (screenResolution. x-width)/2; int topOffset = (screenResolution. y-height)/2; framingRect = new Rect (leftOffset, topOffset, leftOffset + width, topOffset + height); Log. d (TAG, "Calculated framing rect:" + framingRect) ;}return framingRect ;}
I changed the code to adapt to different screen sizes
Public Rect getFramingRect () {Point screenResolution = configManager. getScreenResolution (); if (framingRect = null) {if (camera = null) {return null;} // int width = screenResolution after modification. x * 7/10; int height = screenResolution. y * 7/10; int leftOffset = (screenResolution. x-width)/2; int topOffset = (screenResolution. y-height)/3; framingRect = new Rect (leftOffset, topOffset, leftOffset + width, topOffset + height); Log. d (TAG, "Calculated framing rect:" + framingRect) ;}return framingRect ;}
I occupy 7/10 of the screen width and height
Of course, if the image size is changed, it will occupy a little more memory... the scanning speed will be much faster.
The preceding figure shows the actual size of the read image.
The actual UI beautification is drawn in the ViewfinderView class.
If you have any shortcomings, please leave a message below. Thank you.
Hope to be useful to you
Http://download.csdn.net/detail/aaawqqq/7281577 Resources