android fragment相机,简单的易于集成的Android相机Fragment – Camer...

本文介绍了如何在Android中使用CameraFragment进行集成,包括拍照、录制视频、切换相机、调整闪光灯和设置相机参数等功能。提供了详细的代码示例,展示了如何监听相机状态变化以及获取拍摄结果。
摘要由CSDN通过智能技术生成

CameraFragment

一个简单的易于集成的Android相机Fragment。

QVJrE3.png

//you can configure the fragment by the configuration builder

CameraFragment cameraFragment = CameraFragment.newInstance(new Configuration.Builder().build());

getSupportFragmentManager().beginTransaction()

.replace(R.id.content, cameraFragment, FRAGMENT_TAG)

.commit();

Actions

你可以直接拍摄图片拍摄视频

cameraFragment.takePhotoOrCaptureVideo(callback);

aYfaii.gif

闪光灯可以启动或则禁止:

cameraFragment.toggleFlashMode();

aemEn2.gif

相机类型也可以修改:

cameraFragment.switchCameraTypeFrontBack();

Ibqaq2.gif

相机动作可以修改:

cameraFragment.switchActionPhotoVideo();

ziaU7v.gif

你可以改变所拍摄的照片视频大小?

cameraFragment.openSettingDialog();

3IbINf.gif

Listeners

Result

取回CameraFragmentResultListener中的相机记录/照片

cameraFragment.setResultListener(new CameraFragmentResultListener() {

@Override

public void onVideoRecorded(byte[] bytes, String filePath) {

//called when the video record is finished and saved

startActivityForResult(PreviewActivity.newIntentVideo(MainActivity.this, filePath));

}

@Override

public void onPhotoTaken(byte[] bytes, String filePath) {

//called when the photo is taken and saved

startActivity(PreviewActivity.newIntentPhoto(MainActivity.this, filePath));

}

});

Camera Listener

cameraFragment.setStateListener(new CameraFragmentStateListener() {

//when the current displayed camera is the back

void onCurrentCameraBack();

//when the current displayed camera is the front

void onCurrentCameraFront();

//when the flash is at mode auto

void onFlashAuto();

//when the flash is at on

void onFlashOn();

//when the flash is off

void onFlashOff();

//if the camera is ready to take a photo

void onCameraSetupForPhoto();

//if the camera is ready to take a video

void onCameraSetupForVideo();

//when the camera state is "ready to record a video"

void onRecordStateVideoReadyForRecord();

//when the camera state is "recording a video"

void onRecordStateVideoInProgress();

//when the camera state is "ready to take a photo"

void onRecordStatePhoto();

//after the rotation of the screen / camera

void shouldRotateControls(int degrees);

void onStartVideoRecord(File outputFile);

void onStopVideoRecord();

});

Text

CameraFragment使用CameraFragmentTextListener ping当前记录的持续时间

Widgets

CameraFragment带有一些默认视图

RecordButton,MediaActionSwitchView,FlashSwitchView,CameraSwitchView,CameraSettingsView

umYRna.png

下载

在模块中

compile 'com.github.florent37:camerafragment:1.0.1'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值