List of usage examples for android.hardware Camera open
public static Camera open(int cameraId)
From source file:Main.java
/** * @return the default camera on the device. Return null if there is no camera on the device. *//*from w w w.java2 s. c om*/ public static Camera getDefaultCameraInstance() { return Camera.open(HDMIRXID); }
From source file:Main.java
public static int getCameraFirstId(Context ctx) { if (sCameraFirstIndex != -1) return sCameraFirstIndex; Camera camera = null;/*from ww w.java 2 s . c om*/ try { camera = Camera.open(0); sCameraFirstIndex = 0; camera.release(); camera = null; } catch (Exception ex) { sCameraFirstIndex = 1; } return sCameraFirstIndex; }
From source file:Main.java
/** * * @param position Physical position of the camera i.e Camera.CameraInfo.CAMERA_FACING_FRONT * or Camera.CameraInfo.CAMERA_FACING_BACK. * @return the default camera on the device. Returns null if camera is not available. *//* w w w .ja v a2s . c o m*/ @TargetApi(Build.VERSION_CODES.GINGERBREAD) private static Camera getDefaultCamera(int position) { int id = getDefaultCameraId(position); if (id != -1) { return Camera.open(id); } return null; }
From source file:Main.java
/** * @param position Physical position of the camera i.e Camera.CameraInfo.CAMERA_FACING_FRONT * or Camera.CameraInfo.CAMERA_FACING_BACK. * @return the default camera on the device. Returns null if camera is not available. *//*from w ww .ja v a2 s . co m*/ @TargetApi(Build.VERSION_CODES.GINGERBREAD) private static Camera getDefaultCamera(int position) { // Find the total number of cameras available int mNumberOfCameras = Camera.getNumberOfCameras(); // Find the ID of the back-facing ("default") camera Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); for (int i = 0; i < mNumberOfCameras; ++i) { Camera.getCameraInfo(i, cameraInfo); if (cameraInfo.facing == position) return Camera.open(i); } return null; }
From source file:Main.java
/** * * @param position Physical position of the camera i.e Camera.CameraInfo.CAMERA_FACING_FRONT * or Camera.CameraInfo.CAMERA_FACING_BACK. * @return the default camera on the device. Returns null if camera is not available. */// ww w. j a va2 s . c o m @TargetApi(Build.VERSION_CODES.GINGERBREAD) private static Camera getDefaultCamera(int position) { // Find the total number of cameras available int mNumberOfCameras = Camera.getNumberOfCameras(); // Find the ID of the back-facing ("default") camera Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); for (int i = 0; i < mNumberOfCameras; i++) { Camera.getCameraInfo(i, cameraInfo); if (cameraInfo.facing == position) { return Camera.open(i); } } return null; }
From source file:Main.java
/** * @param position Physical position of the camera i.e Camera.CameraInfo.CAMERA_FACING_FRONT * or Camera.CameraInfo.CAMERA_FACING_BACK. * @return the default camera on the device. Returns null if camera is not available. *//*w w w. ja va 2 s. c om*/ @TargetApi(Build.VERSION_CODES.GINGERBREAD) public static Camera getDefaultCamera(int position) { // Find the total number of cameras available int mNumberOfCameras = Camera.getNumberOfCameras(); // Find the ID of the back-facing ("default") camera Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); for (int i = 0; i < mNumberOfCameras; i++) { Camera.getCameraInfo(i, cameraInfo); if (cameraInfo.facing == position) { try { return Camera.open(i); } catch (Exception e) { e.printStackTrace(); } } } return null; }
From source file:Main.java
/** * * @param position Physical position of the camera i.e Camera.CameraInfo.CAMERA_FACING_FRONT * or Camera.CameraInfo.CAMERA_FACING_BACK. * @return the default camera on the device. Returns null if camera is not available. *///from w ww .j a v a 2 s. c o m @TargetApi(Build.VERSION_CODES.GINGERBREAD) private static Camera getDefaultCamera(int position) { // Find the total number of cameras available int mNumberOfCameras = Camera.getNumberOfCameras(); Log.d(TAG, "getDefaultCamera number:" + mNumberOfCameras + " position:" + position); // Find the ID of the back-facing ("default") camera Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); for (int i = 0; i < mNumberOfCameras; i++) { Camera.getCameraInfo(i, cameraInfo); if (cameraInfo.facing == position) { return Camera.open(i); } } return null; }
From source file:org.webrtc.videoengine.VideoCaptureDeviceInfoAndroid.java
private static String getDeviceInfo() { try {// w w w. jav a 2s . com JSONArray devices = new JSONArray(); for (int i = 0; i < Camera.getNumberOfCameras(); ++i) { CameraInfo info = new CameraInfo(); Camera.getCameraInfo(i, info); String uniqueName = deviceUniqueName(i, info); JSONObject cameraDict = new JSONObject(); devices.put(cameraDict); List<Size> supportedSizes; List<int[]> supportedFpsRanges; Camera camera = null; try { camera = Camera.open(i); Parameters parameters = camera.getParameters(); supportedSizes = parameters.getSupportedPreviewSizes(); supportedFpsRanges = parameters.getSupportedPreviewFpsRange(); Log.d(TAG, uniqueName); } catch (RuntimeException e) { Log.e(TAG, "Failed to open " + uniqueName + ", skipping", e); continue; } finally { if (camera != null) { camera.release(); } } JSONArray sizes = new JSONArray(); for (Size supportedSize : supportedSizes) { JSONObject size = new JSONObject(); size.put("width", supportedSize.width); size.put("height", supportedSize.height); sizes.put(size); } JSONArray mfpsRanges = new JSONArray(); for (int[] range : supportedFpsRanges) { JSONObject mfpsRange = new JSONObject(); // Android SDK deals in integral "milliframes per second" // (i.e. fps*1000, instead of floating-point frames-per-second) so we // preserve that through the Java->C++->Java round-trip. mfpsRange.put("min_mfps", range[Parameters.PREVIEW_FPS_MIN_INDEX]); mfpsRange.put("max_mfps", range[Parameters.PREVIEW_FPS_MAX_INDEX]); mfpsRanges.put(mfpsRange); } cameraDict.put("name", uniqueName); cameraDict.put("front_facing", isFrontFacing(info)).put("orientation", info.orientation) .put("sizes", sizes).put("mfpsRanges", mfpsRanges); } String ret = devices.toString(2); Log.d(TAG, ret); return ret; } catch (JSONException e) { throw new RuntimeException(e); } }
From source file:ac.blitz.acme.video.VideoCaptureDeviceInfoAndroid.java
private static String getDeviceInfo() { try {//from w ww. j a v a2s . c o m JSONArray devices = new JSONArray(); for (int i = 0; i < Camera.getNumberOfCameras(); ++i) { CameraInfo info = new CameraInfo(); Camera.getCameraInfo(i, info); String uniqueName = deviceUniqueName(i, info); JSONObject cameraDict = new JSONObject(); devices.put(cameraDict); List<Size> supportedSizes; List<int[]> supportedFpsRanges; try { Camera camera = Camera.open(i); Parameters parameters = camera.getParameters(); supportedSizes = parameters.getSupportedPreviewSizes(); supportedFpsRanges = parameters.getSupportedPreviewFpsRange(); camera.release(); Log.d(TAG, uniqueName); } catch (RuntimeException e) { Log.e(TAG, "Failed to open " + uniqueName + ", skipping"); continue; } JSONArray sizes = new JSONArray(); for (Size supportedSize : supportedSizes) { JSONObject size = new JSONObject(); size.put("width", supportedSize.width); size.put("height", supportedSize.height); sizes.put(size); } // Android SDK deals in integral "milliframes per second" // (i.e. fps*1000, instead of floating-point frames-per-second) so we // preserve that through the Java->C++->Java round-trip. int[] mfps = supportedFpsRanges.get(supportedFpsRanges.size() - 1); cameraDict.put("name", uniqueName); cameraDict.put("front_facing", isFrontFacing(info)).put("orientation", info.orientation) .put("sizes", sizes).put("min_mfps", mfps[Parameters.PREVIEW_FPS_MIN_INDEX]) .put("max_mfps", mfps[Parameters.PREVIEW_FPS_MAX_INDEX]); } String ret = devices.toString(2); return ret; } catch (JSONException e) { throw new RuntimeException(e); } }
From source file:com.tester.photodetectortest.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);//from w w w . j ava 2s.com mCamera = Camera.open(1); mainContainer = (RelativeLayout) findViewById(R.id.main_container); mPreview = new Preview(this, mCamera); mainContainer.addView(mPreview, 0); pd = new PhotoDetector(this); pd.setLicensePath("sdk.license"); pd.setImageListener(this); pd.setDetectAllEmotions(true); pd.setDetectAllExpressions(true); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mCamera.takePicture(null, null, mPictureCallback); } }); }