当我运行打开前置摄像头的代码时,我看到一个黑屏越来越亮(看起来像是一个摄像头捕捉)。
我的代码:
public class Cam extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cam);
openFrontFacingCameraGingerbread();
}
private Camera openFrontFacingCameraGingerbread()
{
int cameraCount = 0;
Camera camera = null;
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
cameraCount = Camera.getNumberOfCameras();
for (int camIdx = 0; camIdx < cameraCount; camIdx++)
{
Camera.getCameraInfo(camIdx, cameraInfo);
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT)
{
try
{
camera = Camera.open(camIdx);
Log.e("Camera Operation", "Camera opned");
}
catch (RuntimeException e)
{
Log.e("Camera Operation", "Camera failed to open: " + e.getLocalizedMessage());
}
}
}
return camera;
}
}
任何建议都将不胜感激。
注意:使用camera2 API代码显示相同的屏幕。