Reputation: 7756
There is a custom camera implementation in android on this link http://store.ovi.com/content/147853?clickSource=search&pos=1 I wish to know how we can have flash on while capturing images, is it something we will do ourself ? or any api to set camera mode in the example ?
Please help !
Thanks
Upvotes: 2
Views: 2622
Reputation: 414
This is relatively easy after you have an instance of the Camera (Camera.open() will return a Camera instance).
First you need to get the Camera Parameters with
Camera.Parameters params = yourCameraInstance.getParameters();
Next you need to check if the device being used is capable of the flash mode you wish to implement, just in case you try to tell the device to turn on the flash and it can't. This would cause a crash.
List<String> flashModes = params.getSupportedFlashModes();
This returns a list of all the flash modes the device is capable of in String form. For example, the list should contain something like: FLASH_MODE_AUTO, FLASH_MODE_ON, FLASH_MODE_OFF, ect.
Then do something like:
if (flashModes.contains(Camera.Parameters.FLASH_MODE_AUTO)) {
params.setFlashMode(Camera.Parameters.FLASH_MODE_AUTO);
}
Finally, set your new params to your camera instance like so:
yourCameraInstance.setParameters(params);
Likewise, you can check for other camera features in the same fashion:
List<String> focusModes = params.getSupportedFocusModes();
if (focusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) {
params.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
}
yourCameraInstance.setParameters(params);
Hope this helps someone!
Upvotes: 2
Reputation: 45503
You can set the desired flash mode as part of the parameters you pass in the Camera
object using setParameters(Camera.Parameters params)
. Refer to the setFlashMode(String)
method on the parameters, supplying either FLASH_MODE_ON
, FLASH_MODE_OFF
or FLASH_MODE_AUTO
.
Camera camera = Camera.open();
Camera.Parameters params = new Camera.Parameters();
params.setFlashMode(Camera.Parameters.FLASH_MODE_ON);
// ... set other parameters
camera.setParameters(params);
Upvotes: 4