In our zxing framework for the two-dimensional code scanning, we will find that the mobile phone with the resolution of the increase, the scan box will be smaller, in 1920*1280 and 1280*720 is relatively normal, but Samsung's several mobile phones note4,5,s6, and other mobile phone resolution of up to 2560 *1440, even some mobile phones up to 3660 of the bar can't remember.
When these phones scan, pop-up scan activity middle Surfaceview Scan window Small is also drunk,
Do not say the solution:
1: Find the intent that initiates the scan:
Intent opencameraintent = new Intent (context,captureactivity.class);
Startactivityforresult (opencameraintent,0);
2: Follow captureactivity class, search in class:Cameramanager, follow it in Cameramanager class: The top four line parameter is the setting width high,
private static final int min_frame_width = (int) dp_sp_px_utils.dp2px (MyApplication.instance.getResources (), (); private static final int min_frame_height = (int) dp_sp_px_utils.dp2px (MyApplication.instance.getResources (), (); private static final int max_frame_width = (int) dp_sp_px_utils.dp2px (MyApplication.instance.getResources (), +); private static final int max_frame_height = (int) dp_sp_px_utils.dp2px (MyApplication.instance.getResources (), 240);
I have a DP conversion behind it so that the screen scan window size is fixed for each resolution. Solve the problem perfectly.
Second question: the picture will be compressed after each scan
Workaround: Locate the Cameraconfigurationmanager.java class under the camera package under the Zxing package and modify:
Search initfromcameraparameters This method, find Log.d under this method (TAG, "screen resolution:" + screenresolution); In this sentence, add the following code to this phrase:
Point Screenresolutionforcamera = new Point (); screenresolutionforcamera.x = screenresolution.x; SCREENRESOLUTIONFORCAMERA.Y = SCREENRESOLUTION.Y; Preview size is all something like 480*320, and other 320*480 if (screenresolution.x < SCREENRESOLUTION.Y) { screenresolutionforcamera.x = SCREENRESOLUTION.Y; SCREENRESOLUTIONFORCAMERA.Y = screenresolution.x; }
Then there is a line of code like this:
[Java]View Plaincopy
- Cameraresolution = getcameraresolution (parameters, screenresolution);
Changed to Screenresolutionforcamera in Screenresolution
As follows:
[Java]View Plaincopy
- Cameraresolution = getcameraresolution (Parameters, Screenresoluti
Save, run the perfect solution, here are two-dimensional code scanning and QR code generation demo do not need points, we learn from each other, common with progress, there are problems can be put forward in the comment area.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android zxing frame scan fix scan box size, picture compression problem