第九章:CameraX实现防微信朋友圈拍照和录屏(附oss上传下载manager

} else {

canvas.drawCircle(width / 2, height / 2, radius, fillPaint);

}

}

public void setMaxDuration(int maxDuration) {

this.progressMaxValue = maxDuration * 1000 / PROGRESS_INTERVAL;

}

public void setOnRecordListener(onRecordListener listener) {

mListener = listener;

}

@Override

public boolean onLongClick(View v) {

if (mListener != null) {

mListener.onLongClick();

}

return true;

}

@Override

public void onClick(View v) {

if (mListener != null) {

mListener.onClick();

}

}

public interface onRecordListener {

void onClick();

void onLongClick();

void onFinish();

}

}

<?xml version="1.0" encoding="utf-8"?>

  • 拍照xml
<?xml version="1.0" encoding="utf-8"?>

<layout xmlns:android=“http://schemas.android.com/apk/res/android”

xmlns:app=“http://schemas.android.com/apk/res-auto”>

<FrameLayout

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:orientation=“vertical”>

<TextureView

android:id="@+id/texture_view"

android:layout_width=“match_parent”

android:layout_height=“match_parent” />

<TextView

android:id="@+id/capture_tips"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_gravity=“center_horizontal|bottom”

android:layout_marginBottom=“200dp”

android:text=“轻触拍照,长按摄像”

android:textColor="#ffffff" />

<cn.yumakeji.lib_common.view.RecordView

android:id="@+id/record_view"

android:layout_width=“100dp”

android:layout_height=“100dp”

android:layout_gravity=“bottom|center_horizontal”

android:layout_marginBottom=“60dp”

app:duration=“10”

app:fill_color="#ffffff"

app:progress_color="@color/colorAccent"

app:progress_width=“4dp”

app:radius=“40dp” />

  • CaptureActivity

import cn.yumakeji.jetpackroomstudy.R;

import cn.yumakeji.jetpackroomstudy.databinding.ActivityCaptureBinding;

import cn.yumakeji.lib_common.view.RecordView;

public class CaptureActivity extends AppCompatActivity {

public static final int REQ_CAPTURE = 10001;

private ActivityCaptureBinding mBinding;

private Preview preview;

private ImageCapture imageCapture;

private VideoCapture videoCapture;

private TextureView textureView;

private String outputFilePath;

public static void startActivityForResult(Activity activity) {

Intent intent = new Intent(activity, CaptureActivity.class);

activity.startActivityForResult(intent, REQ_CAPTURE);

}

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

mBinding = DataBindingUtil.setContentView(this, R.layout.activity_capture);

}

@Override

public void onAttachedToWindow() {

super.onAttachedToWindow();

bindCameraX();

initListener();

}

/**

  • 前后摄像头

*/

private CameraX.LensFacing mLensFacing = CameraX.LensFacing.BACK;

/**

  • 旋转角度

*/

private int rotation = Surface.ROTATION_0;

/**

  • 分辨率

*/

private Size resolution = new Size(1280, 720);

/**

  • 宽高比

*/

private Rational rational = new Rational(9, 16);

/**

  • 初始化配置

*/

@SuppressLint(“RestrictedApi”)

private void bindCameraX() {

//查询一下当前要使用的设备摄像头(比如后置摄像头)是否存在

boolean hasAvailableCameraId = false;

try {

hasAvailableCameraId = CameraX.hasCameraWithLensFacing(mLensFacing);

} catch (CameraInfoUnavailableException e) {

e.printStackTrace();

}

if (!hasAvailableCameraId) {

Toast.makeText(this, “无可用的设备cameraId!,请检查设备的相机是否被占用”, Toast.LENGTH_LONG).show();

finish();

return;

}

//查询一下是否存在可用的cameraId.形式如:后置:“0”,前置:“1”

String cameraIdForLensFacing = null;

try {

cameraIdForLensFacing = CameraX.getCameraFactory().cameraIdForLensFacing(mLensFacing);

} catch (Camer

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值