Android zxing frame scan fix scan box size, picture compression problem

Source: Internet
Author: User

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
    1. Cameraresolution = getcameraresolution (parameters, screenresolution);

Changed to Screenresolutionforcamera in Screenresolution
As follows:

[Java]View Plaincopy
    1. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.