SoFunction
Updated on 2025-03-08

Solution to the problem of stretching the picture by scanning the QR code on Android Zxing

It is still the one who takes over the project. The QR code scanning integrates zxing, and the image on the scanning interface has obvious tensile deformation.

According to past experience, this kind of problem is generally caused by misalignment of x and y axes. Handling the problem of x and y axes can generally solve the problem.

Due to this problem, many people have encountered it before and shared it online, so I don’t need to recreate the wheel here.

Here is a blog:Android Zxing QR code scan picture stretch, using the above method,

Successfully solved the problem of image stretching.

The solution is as follows:

Modify the initFromCameraParameters method:

void initFromCameraParameters(Camera camera) {
  parameters = ();
 previewFormat = ();
 previewFormatString = ("preview-format");
 (TAG, "Default preview format: " + previewFormat + '/' + previewFormatString);
 WindowManager manager = (WindowManager) (Context.WINDOW_SERVICE);
 Display display = ();
 screenResolution = new Point((), ());
 (TAG, "Screen resolution: " + screenResolution);

 //added
 Point screenResolutionForCamera = new Point();
  = ;
  = ;
 // preview size is always something like 480*320, other 320*480
 if ( < ) {
   = ;
   = ;
 }
 cameraResolution = getCameraResolution(parameters, screenResolutionForCamera);

// cameraResolution = getCameraResolution(parameters, screenResolution);
 (TAG, "Camera resolution: " + screenResolution);
 }

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.