我們有一款應用程序,可與我們所有支持的Android手機「三星Galaxy S5」除外。我們的應用程序使用相機近距離拍攝照片。 我們需要在整個拍攝過程中都需要使用手電筒模式。我們檢查支持的參數並設置支持的值。三星Galaxy S5相機火炬不工作
該參數設置,但事件要麼永遠不會被解僱或相機忽略我的設置。我使用OpenCamera進行了測試,他們的應用程序能夠打開火炬,但我無法找到我如何設置自己的參數與如何設置自己的參數之間的區別。
這裏是我們的代碼:
//Set all camera parameters(flash, focus, white balance, etc)
private void setCameraParameters()
{
//Rotate the orientation of the preview to match orientation of device
camera.setDisplayOrientation(getCameraRotation());
//A Parameters object must be used to set the other parameters.
Parameters params = camera.getParameters();
//Flash Mode to Torch if supported
if(params.getSupportedFlashModes().contains("torch"))
{
// Torch mode
params.setFlashMode(Parameters.FLASH_MODE_TORCH);
}
//Focus Mode to Macro if supported, Auto if not
if(params.getSupportedFocusModes().contains("macro"))
{
//Macro focus mode
params.setFocusMode(Parameters.FOCUS_MODE_MACRO);
}
else
{
//Auto focus mode
params.setFocusMode(Parameters.FOCUS_MODE_AUTO);
}
//White Balance mode to Auto if available.
List<String> supported_white = params.getSupportedWhiteBalance();
if(supported_white!=null)
{
if(supported_white.contains("auto"))
{
params.setWhiteBalance(Parameters.WHITE_BALANCE_AUTO);
}
}
// Auto Exposure Lock to false if available
if(params.isAutoExposureLockSupported())
{
params.setAutoExposureLock(false);
}
// Auto White Balance Lock if available.
if(params.getAutoWhiteBalanceLock())
{
params.setAutoWhiteBalanceLock(false);
}
//JPEG quality set to 100(highest)
{
params.setJpegQuality(100);
}
//Set focus area and metering area
List<Camera.Area> focusArea = calculateFocusArea();
params.setFocusAreas(focusArea);
params.setMeteringAreas(focusArea);
Camera.Size size = pickCameraSize(params.getSupportedPictureSizes());
params.setPictureSize(size.width, size.height);
//Set new parameters for camera
camera.setParameters(params);
boolean torch = getTorchState(camera);
}
// Added this method from zxing github to see if the value is being set
boolean getTorchState(Camera camera) {
if (camera != null) {
Camera.Parameters parameters = camera.getParameters();
if (parameters != null) {
String flashMode = camera.getParameters().getFlashMode();
return flashMode != null
&& (Camera.Parameters.FLASH_MODE_ON.equals(flashMode) || Camera.Parameters.FLASH_MODE_TORCH
.equals(flashMode));
}
}
return false;
}
添加了一個方法來檢查火炬狀態。即使它沒有打開,它也會被設置。在本機相機應用程序中,手電筒在設置時會自動啓動。所以,現在我正在查看Google代碼。仍然希望有人會有一些有用的信息。 :-) – Patricia 2015-01-27 00:34:36