代码拉取完成,页面将自动刷新
1.在项目根目录下的build.gradle文件中,
allprojects {
repositories {
maven {
url 'https://s01.oss.sonatype.org/content/repositories/snapshots/'
}
}
}
2.在entry模块的build.gradle文件中
dependencies {
implementation 'com.gitee.chinasoft_ohos:CameraFragment:1.0.1'
}
在sdk6,DevEco Studio2.2 Beta1下项目可直接运行 如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, 并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下
初始化后置摄像头配置
CameraFraction cameraFraction = CameraFraction.newInstance(new Configuration.Builder()
.setCamera(Configuration.CAMERA_FACE_REAR).build())
// 初始化得到的 cameraFraction 添加到StackLayout中
getFractionManager().startFractionScheduler()
.add(ResourceTable.Id_content, cameraFraction, FRAGMENT_TAG)
.submit();
// 行为
你可以直接用它拍照/录像
cameraFraction.takePhotoOrCaptureVideo(callback);
cameraFraction.takePhotoOrCaptureVideo(callback, directoryPath, fileName);
Flash可以启用/禁用(' AUTO ' / ' OFF ' / ' ON ')
cameraFraction.toggleFlashMode();
相机类型可以修改('后' / '前')
```java
cameraFraction.switchCameraTypeFrontBack();
你可以改变捕获的照片/视频大小
cameraFraction.openSettingDialog();
//结果
返回相机记录/照片的结果 CameraFragmentResultListener
cameraFraction.setResultListener(new CameraFragmentResultListener() {
@Override
public void onVideoRecorded(byte[] bytes, String filePath) {
// 视频录制完成并保存后调用
startActivityForResult(PreviewActivity.newIntentVideo(MainActivity.this, filePath));
}
@Override
public void onPhotoTaken(byte[] bytes, String filePath) {
// 在拍摄和保存照片时调用
startActivity(PreviewActivity.newIntentPhoto(MainActivity.this, filePath));
}
});
//相机监听器
cameraFraction.setStateListener(new CameraFragmentStateListener() {
//当前显示的相机是背面
void onCurrentCameraBack();
//当前显示的摄像头为正面时
void onCurrentCameraFront();
//当闪光灯处于自动模式时
void onFlashAuto();
//当闪光灯亮着的时候
void onFlashOn();
//当闪光灯熄灭时
void onFlashOff();
//如果相机已经准备好拍照了
void onCameraSetupForPhoto();
//如果相机准备好拍视频
void onCameraSetupForVideo();
//当摄像头状态为“准备录制视频”时
void onRecordStateVideoReadyForRecord();
//当摄像头状态为“录制视频”时
void onRecordStateVideoInProgress();
//当相机状态为“准备好拍照”时
void onRecordStatePhoto();
//旋转屏幕/摄像机后
void shouldRotateControls(int degrees);
void onStartVideoRecord(File outputFile);
void onStopVideoRecord();
});
//文本
CameraFraction可以用当前记录的持续时间提示CameraFragmentTextListener
//小工具
CameraFraction带有一些默认视图
RecordButton
, MediaActionSwitchView
, FlashSwitchView
, CameraSwitchView
, CameraSettingsView
CodeCheck代码测试无异常
CloudTest代码测试无异常
病毒安全检测通过
当前版本demo功能与原组件基本无差异
Copyright 2017 florent37, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型