Rafael
Rafael

Reputation: 155

Code my android flash camera like native camera

I developed a camera in my app but when a set flash mode on and take a picture the light that comes out is to short and doesn't works on final picture. How can I develop my flash light like native camera that shows 2 or 3 levels of flashlight when takes a picture?

Upvotes: 1

Views: 2450

Answers (2)

Rafael
Rafael

Reputation: 155

I solved the problem. When I click the takepicture button first I turn on the flashlight with param.setFlashMode(Parameters.FLASH_MODE_TORCH); for 1 second, after I set param.setFlashMode(Parameters.FLASH_MODE_ON); and call takepicture method. This way I can simulate native camera flash

Upvotes: 2

Lucifer
Lucifer

Reputation: 29672

You need to make your flash light to work as torch.

First, apply permission in AndroidManifest.xml as follows,

<uses-feature android:name="android.hardware.camera" />

<uses-permission
    android:name="android.permission.FLASHLIGHT"
    android:permissionGroup="android.permission-group.HARDWARE_CONTROLS"
    android:protectionLevel="normal" />

<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.flash" />

Now use the below code to start the flash light

Camera camera = Camera.open();     
Parameters param = camera.getParameters();
param.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(param);
camera.startPreview();

and the below code is for off the flash light

camera.stopPreview();
camera.release();

Upvotes: 0

Related Questions