TakePhotoX

Camerax based photography, video, QR code scanning

Github source: github.com/yijiebuyi/T…

Download the Demo

Click to download APK

Installation password: 123456

function

  • Support the video
  • Supports switching between front and rear cameras
  • Support 4:3 16:9 1:1 picture shooting
  • Supports QR code scanning and identification
  • Support light control

use

  • 1. Add the following code to project build.gradle
allprojects {
    repositories{... maven { url"https://jitpack.io"}}}Copy the code
  • 2. Rely on androidx

dependencies {
  implementation 'com. Making. Yijiebuyi: TakePhotoX: v1.2.2'
}

Copy the code

First, take photos basic usage:

  • Create your own camera UI using CameraView
// The external functions provided by CameraView, see ICamera, IFlashLight for details

/ / CameraView use
private CameraView mCameraView;
//================ common functions are as follows: =================
/ / photo
mCameraView.take();
/ / af
mCameraView.focus(float x, float y, float rawX, float rawY);
// Switch front and back
mCameraView.switchFace();
// The camera toggles the preview scale and the photo scale
mCameraView.switchAspect(@ExAspectRatio.ExRatio int ratio);
    
//================ set callback ======================
// Set the photo callback
mCameraView.setOnCameraListener(OnCameraListener l);
// Set the focus callback
mCameraView.setOnFocusListener(OnFocusListener l);    
// Set the image analysis callback
mCameraView.setOnImgAnalysisListener(OnImgAnalysisListener l);
// Set the camera switch callback
mCameraView.setOnCameraFaceListener(OnCameraFaceListener l);
// Set the camera preview view layout and size change callback
mCameraView.setOnPreviewLayoutListener(OnPreviewLayoutListener l);
Copy the code
  • You can also use CameraFragment and use the UI provided by default
   FragmentManager fm = getSupportFragmentManager();
   FragmentTransaction ft = fm.beginTransaction();
   final CameraFragment cfg = new CameraFragment();

   CameraOption option = new CameraOption.Builder(ExAspectRatio.RATIO_16_9)
           .faceFront(false) //false: Enable the rear camera
           .build();

   Bundle data = new Bundle();
   data.putSerializable(CameraFragment.KEY_CAMERA_OPTION, option);
   cfg.setArguments(data);
   cfg.setOnCameraListener(new OnCameraListener() {
       @Override
       public void onTaken(Uri uri) {
           // Returns the photo URI
       }

       @Override
       public void onCancel(a) { finish(); }});Copy the code
  • Use CameraXActivity directly
startActivityForResult(new Intent(MainActivity.this, CameraXActivity.class), 1000);

@Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if(resultCode == RESULT_OK && data ! =null) {
            // Return the address of the picture takenUri uri = data.getData(); }}Copy the code

Two, video shooting basic usage:

  • Using VideoXActivity
@Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if(resultCode == RESULT_OK && data ! =null) { Uri uri = data.getData(); TextView tv = findViewById(R.id.photo_path); tv.setText(uri.getPath()); }}Copy the code

Three, two-dimensional code scanning basic usage:

Note: need to rely on zxing packages

  • Qr code scan using QrCodeFragment directly
setWrapQrCodeCallback
Copy the code
  • Qr code scan using QRCodeView
    mQRCodeView = new QRCodeView(mContext);
    mQRCodeView.setOnQrCodeCallback(QrCodeCallback callback);
    mQRCodeView.setScannerFrameOption(new ScannerFrameOption.Builder()
            .frameMode(ScannerFrameOption.FrameMode.MODE_FRAME_SQUARE)
            .frameRatio(0.6 f)
            .build());

   //add mQRCodeView
Copy the code