-
Notifications
You must be signed in to change notification settings - Fork 3k
PictureSelector 3.0 如何自定义相机?
Luck edited this page Jan 9, 2022
·
8 revisions
以下以SimpleCameraX为例,详情请参阅文档
1、Application实现接口CameraXConfig.Provider
@NonNull
@Override
public CameraXConfig getCameraXConfig() {
return CameraXConfig.Builder.fromConfig(Camera2Config.defaultConfig())
.setMinimumLoggingLevel(Log.ERROR).build();
}
2、实现.setCameraInterceptListener();方法
.setCameraInterceptListener(new OnCameraInterceptListener() {
@Override
public void openCamera(Fragment fragment, int cameraMode, int requestCode) {
// 注意* 如果你实现自己的拍照库,需要在Activity的.setResult(); 给Intent MediaStore.EXTRA_OUTPUT 保存拍照后的路径;
if (cameraMode == SelectMimeType.ofAudio()) {
Toast.makeText(getContext(), "自定义录音功能,请自行扩展", Toast.LENGTH_LONG).show();
} else {
SimpleCameraX camera = SimpleCameraX.of();
camera.setCameraMode(cameraMode);
camera.setOutputPathDir(config.outPutCameraDir);
camera.setImageEngine(new CameraImageEngine() {
@Override
public void loadImage(Context context, String url, ImageView imageView) {
Glide.with(context).load(url).into(imageView);
}
});
camera.start(fragment.getActivity(), fragment, requestCode);
}
}
});