我想要录制带有闪光灯的视频,以便专注于捕捉。
答案 0 :(得分:2)
将此添加到您的清单
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
检查设备是否有摄像头
boolean hasFlash = getApplicationContext().getPackageManager()
.hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
Camera camera = Camera.open();
Parameters params = camera.getParameters();
打开闪光灯
params = camera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(params);
camera.startPreview();
关闭闪光灯
params = camera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(params);
camera.stopPreview();
在这种情况下,您可以使用SurfaceView 将此添加到您的xml
<SurfaceView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/surface"
android:layout_weight="2"/>
然后在活动中
surfaceview=(SurfaceView)findViewById(R.id.surface);
surfaceholder=surfaceview.getHolder();
surfaceholder.addCallback(this);
surfaceholder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
@Override
public void surfaceCreated(SurfaceHolder surfaceHolder) {
try {
camera = Camera.open();
android.hardware.Camera.Parameters params = camera.getParameters();
params = camera.getParameters();
params.setFlashMode(android.hardware.Camera.Parameters.FLASH_MODE_TORCH);
camera.setParameters(params);
camera.setPreviewDisplay(surfaceholder);
camera.startPreview();
// Toast.makeText(getApplication(), "Create", Toast.LENGTH_LONG).show();
} catch (IOException e) { }
}