相机闪烁并消失,是否有兼容措施?
Camera c = null;
try {
c = Camera.open(0); // attempt to get a Camera instance
Camera.Parameters p = c.getParameters();
p.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
c.setParameters(p);
c.startPreview();
} catch (Exception e) {
// Camera is not available (in use or does not exist)
Log.e(TAG,"exception e"+e.getMessage());
}
答案 0 :(得分:0)
1.检查闪存许可
c = Camera.open();
Camera.Parameters params=null;
params= c.getParameters();
List<String> supportedFlashModes = sParams.getSupportedFlashModes();
if (supportedFlashModes != null) {
if (supportedFlashModes.contains(Camera.Parameters.FLASH_MODE_TORCH)) {
sParams.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
} else if (supportedFlashModes.contains(Camera.Parameters.FLASH_MODE_ON)) {
sParams.setFlashMode(Camera.Parameters.FLASH_MODE_ON);
} else c = null;
} else Log.d(TAG, "Camera is null.");
if (c != null) {
Log.d(TAG, "Flash disponibile (" + sParams.getFlashMode() + ")");
c.setParameters(sParams);
c.autoFocus(null);
}
2.使用SurfaceView的一些特殊情况:
public void surfaceCreated(SurfaceHolder holder) {
if(mCamera!=null){
mCamera.release();
}
mCamera=Camera.open();
mCamera.setParameters(PerviousParams);
mCamera.startPreview();
}
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
if(mCamera!=null){
mCamera.release();
}
mCamera=Camera.open();
mCamera.setParameters(PerviousParams);
mCamera.startPreview();
}