Customized camera view & rotation in Zxing for QR code?

后端 未结 3 938
迷失自我
迷失自我 2021-01-12 01:35

I am working with such a great library zxing to read QR code. I already got QR code successfully.

Now, My application runs in landscape mode and camera takes the who

3条回答
  •  耶瑟儿~
    2021-01-12 02:25

    I was in same problem and got stuck about 2 days on it. Actually you have to do some tasks to achieve your goal.

    1. Download Zxing library for read QR code.. (Hope you have already)
    2. Create a project and add Zxing library.
    3. Your main.xml file should look like:

      
      
      
      
      
      
          
      
      
      
      
    4. Your main Activity should look like:

       public class ScannerActivity extends CaptureActivity {
      
              @Override
              public void onCreate(Bundle savedInstanceState) {
                  super.onCreate(savedInstanceState);
                  setContentView(R.layout.main);
      
              }
      
              @Override 
              public void handleDecode(Result rawResult, Bitmap barcode) 
              {
         Toast.makeText(this.getApplicationContext(), "Scanned code " + rawResult.getText(), Toast.LENGTH_LONG).show();
              }
          }
      
    5. In the manifest file add permission following:

       
      
    6. and finally very IMPORTANT task you need to do for camera rotation problem, replace the following method into the

    CameraManager.java (in the package com.google.zxing.client.android.camera)

    @SuppressLint("NewApi") public void startPreview() {
        Camera theCamera = camera;
        if (theCamera != null && !previewing) {
            theCamera.setDisplayOrientation(90);
          theCamera.startPreview();
          previewing = true;
        }
      }
    

    that's all . run and enjoy :-)

    thanks..

提交回复
热议问题