List of usage examples for android.hardware Camera getCameraInfo
public static void getCameraInfo(int cameraId, CameraInfo cameraInfo)
From source file:com.ktouch.kdc.launcher4.camera.CameraManager.java
/** * Sets the current orientation of the device * @param orientation The orientation, in degrees *//*from w w w . ja v a 2 s . co m*/ public void setOrientation(int orientation) { orientation += 90; if (mOrientation == orientation) return; mOrientation = orientation; // Rotate the pictures accordingly (display is kept at 90 degrees) Camera.CameraInfo info = new android.hardware.Camera.CameraInfo(); Camera.getCameraInfo(mCurrentFacing, info); //orientation = (360 - orientation + 45) / 90 * 90; int rotation = 0; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { rotation = (info.orientation - orientation + 360) % 360; } else { // back-facing camera rotation = (info.orientation + orientation) % 360; } //setParameterAsync("rotation", Integer.toString(rotation)); }
From source file:com.prt.thirdeye.CamManager.java
/** * Sets the current orientation of the device * // ww w . ja v a 2 s. c o m * @param orientation * The orientation, in degrees */ public void setOrientation(int orientation) { orientation += 90; if (mOrientation == orientation) return; mOrientation = orientation; // Rotate the pictures accordingly (display is kept at 90 degrees) Camera.CameraInfo info = new android.hardware.Camera.CameraInfo(); Camera.getCameraInfo(mCurrentFacing, info); // orientation = (360 - orientation + 45) / 90 * 90; int rotation = 0; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { rotation = (info.orientation - orientation + 360) % 360; } else { // back-facing camera rotation = (info.orientation + orientation) % 360; } // setParameterAsync("rotation", Integer.toString(rotation)); }
From source file:com.gsma.rcs.ri.sharing.video.OutgoingVideoSharing.java
/** * Open the camera//from ww w . jav a 2 s . co m * * @param cameraId Camera ID */ private void openCamera(CameraOptions cameraId) { Method method = getCameraOpenMethod(); if (mNbfCameras > 1 && method != null) { try { int hCamId = 0; if (cameraId == CameraOptions.FRONT) { Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); for (int id = 0; id < mNbfCameras; id++) { Camera.getCameraInfo(id, cameraInfo); if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { hCamId = id; break; } } } mCamera = (Camera) method.invoke(mCamera, new Object[] { hCamId }); mOpenedCameraId = cameraId; } catch (Exception e) { mCamera = Camera.open(); mOpenedCameraId = CameraOptions.BACK; } } else { mCamera = Camera.open(); mOpenedCameraId = CameraOptions.BACK; } if (mVideoPlayer != null) { mVideoPlayer.setCameraId(mOpenedCameraId.getValue()); } if (LogUtils.isActive) { Log.d(LOGTAG, "Open camera ".concat(mOpenedCameraId.toString())); } }
From source file:com.CloudRecognition.CloudReco.java
private void setSampleAppMenuSettings() { SampleAppMenuGroup group;/*from w w w . j a va 2 s. c o m*/ group = mSampleAppMenu.addGroup("", false); group.addTextItem(getString(R.string.close_app), -1); group = mSampleAppMenu.addGroup("", false); group.addTextItem(getString(R.string.menu_back), 6); group = mSampleAppMenu.addGroup("", true); group.addSelectionItem(getString(R.string.menu_extended_tracking), CMD_EXTENDED_TRACKING, false); group.addSelectionItem(getString(R.string.menu_contAutofocus), CMD_AUTOFOCUS, mContAutofocus); mFlashOptionView = group.addSelectionItem(getString(R.string.menu_flash), CMD_FLASH, false); CameraInfo ci = new CameraInfo(); boolean deviceHasFrontCamera = false; boolean deviceHasBackCamera = false; for (int i = 0; i < Camera.getNumberOfCameras(); i++) { Camera.getCameraInfo(i, ci); if (ci.facing == CameraInfo.CAMERA_FACING_FRONT) deviceHasFrontCamera = true; else if (ci.facing == CameraInfo.CAMERA_FACING_BACK) deviceHasBackCamera = true; } if (deviceHasBackCamera && deviceHasFrontCamera) { group = mSampleAppMenu.addGroup(getString(R.string.menu_camera), true); group.addRadioItem(getString(R.string.menu_camera_front), CMD_CAMERA_FRONT, false); group.addRadioItem(getString(R.string.menu_camera_back), CMD_CAMERA_REAR, true); } mSampleAppMenu.attachMenu(); }
From source file:com.ezartech.ezar.videooverlay.ezAR.java
private int getCameraId(CameraDirection cameraDir) { // Find number of cameras available int numberOfCameras = Camera.getNumberOfCameras(); Log.d(TAG, "Cameras:" + numberOfCameras); // Find ID of the back-facing ("default") camera Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); int cameraIdToOpen = UNDEFINED; for (int i = 0; i < numberOfCameras; i++) { Camera.getCameraInfo(i, cameraInfo); Log.d(TAG, "Camera facing:" + cameraInfo.facing); if (cameraInfo.facing == cameraDir.getDirection()) { cameraIdToOpen = i;/*from ww w .jav a 2s . c o m*/ break; } } if (cameraIdToOpen == UNDEFINED) { cameraIdToOpen = numberOfCameras - 1; } return cameraIdToOpen; }
From source file:com.kjsaw.alcosys.ibacapp.IBAC.java
public void surfaceCreated(SurfaceHolder holder) { // TODO Auto-generated method stub int cameraCount = 0; 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); camera.setDisplayOrientation(90); Session.isFacingCamera = true; return; } catch (RuntimeException re) { Logging.d(re.toString()); }//from w w w .ja va2 s.c o m } } camera = Camera.open(); camera.setDisplayOrientation(90); }
From source file:com.aimfire.demo.CamcorderActivity.java
public void setCameraPreviewOrientation() { if (BuildConfig.DEBUG) Log.d(TAG, "setCameraPreviewOrientation"); Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(mCameraId, info); int rotation = getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0;//from w w w . j a va 2 s .co m break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { // front-facing result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } mCamera.setDisplayOrientation(result); }
From source file:com.aimfire.demo.CamcorderActivity.java
public void setCameraRotation() { if (BuildConfig.DEBUG) Log.d(TAG, "setCameraRotation"); OrientationEventListener listener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL) { @Override/*w ww . j ava2 s.c o m*/ public void onOrientationChanged(int orientation) { if (orientation == ORIENTATION_UNKNOWN) return; Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(mCameraId, info); orientation = (orientation + 45) / 90 * 90; int rotation = 0; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { rotation = (info.orientation - orientation + 360) % 360; } else { // back-facing camera rotation = (info.orientation + orientation) % 360; } Camera.Parameters parms = mCamera.getParameters(); parms.setRotation(rotation); mCamera.setParameters(parms); } }; if (listener.canDetectOrientation()) { listener.enable(); } }
From source file:com.aimfire.demo.CamcorderActivity.java
/** * Opens a camera, and attempts to establish preview mode at the specified width * and height.// w ww .j a v a 2 s. c o m * <p> * Sets mCameraPreviewWidth and mCameraPreviewHeight to the actual width/height * of the preview. */ private boolean openCamera(int desiredFacing, int videoQuality) { if (mCamera != null) { if (BuildConfig.DEBUG) Log.e(TAG, "openCamera: camera already initialized"); FirebaseCrash.report(new Exception("CamcorderActivity openCamera: camera already initialized")); return false; } final Camera.CameraInfo info = new Camera.CameraInfo(); /* * Try to find camera with desired facing */ int numCameras = Camera.getNumberOfCameras(); if (numCameras == 0) { if (BuildConfig.DEBUG) Log.e(TAG, "openCamera: No camera found, exiting"); FirebaseCrash.report(new Exception("openCamera: No camera found, exiting")); return false; } mCameraId = -1; for (int i = 0; i < numCameras; i++) { Camera.getCameraInfo(i, info); if (info.facing == desiredFacing) { mCameraId = i; break; } } if (mCameraId == -1) { if (BuildConfig.DEBUG) Log.d(TAG, "openCamera: No camera with desired facing found; opening default"); FirebaseCrash.report(new Exception("openCamera: No camera with desired facing found; opening default")); mCameraId = 0; } try { mCamera = Camera.open(mCameraId); } catch (RuntimeException e) { if (BuildConfig.DEBUG) Log.e(TAG, "openCamera: cannot open camera!"); FirebaseCrash.report(e); return false; } mCameraOrientation = info.orientation; mCameraFacing = info.facing; mCameraParams = mCamera.getParameters(); CameraUtils.setCamParams(mCameraParams); /* * if we can find a supported video/preview size that's the same as our desired size, * use it. otherwise, use the best quality supported by the camera. */ mSupportedVideoQualities = CameraUtils.getSupportedVideoQualities(); if ((mSupportedVideoQualities & (1 << mQualityPref)) == 0) { if (BuildConfig.DEBUG) Log.d(TAG, "openCamera: desired quality " + mQualityPref + " not supported"); mQualityPref = CameraUtils.getMaxVideoQuality(); /* * since this device doesn't support whatever quality preference we had before, * we save the best quality that it does support */ updateQualityPref(mQualityPref); } mCameraParams.setPreviewSize(MainConsts.VIDEO_DIMENSIONS[mQualityPref][0], MainConsts.VIDEO_DIMENSIONS[mQualityPref][1]); AspectFrameLayout afl = (AspectFrameLayout) findViewById(R.id.cameraPreview_frame); afl.setAspectRatio((float) MainConsts.VIDEO_DIMENSIONS[mQualityPref][0] / (float) MainConsts.VIDEO_DIMENSIONS[mQualityPref][1]); /* * give the camera a hint that we're recording video. this can have a big * impact on frame rate. */ mCameraParams.setRecordingHint(true); /* * disable all the automatic settings, in the hope that frame rate will * be less variable * * TODO: if any of the default modes are not available then we need to * sync it with the remote device */ List<String> modes; modes = mCameraParams.getSupportedFocusModes(); if (modes != null) { for (String mode : modes) { if (mode.contains(Camera.Parameters.FOCUS_MODE_INFINITY)) { mCameraParams.setFocusMode(Camera.Parameters.FOCUS_MODE_INFINITY); break; } } } modes = mCameraParams.getSupportedFlashModes(); if (modes != null) { for (String mode : modes) { if (mode.contains(Camera.Parameters.FLASH_MODE_OFF)) { mCameraParams.setFlashMode(Camera.Parameters.FLASH_MODE_OFF); break; } } } /* modes = mCameraParams.getSupportedWhiteBalance(); if(modes != null) { for(String mode : modes) { if(mode.contains(Camera.Parameters.WHITE_BALANCE_FLUORESCENT)) { mCameraParams.setWhiteBalance(Camera.Parameters.WHITE_BALANCE_FLUORESCENT); break; } } } modes = mCameraParams.getSupportedSceneModes(); if(modes != null) { for(String mode : modes) { if(mode.contains(Camera.Parameters.SCENE_MODE_PORTRAIT)) { mCameraParams.setSceneMode(Camera.Parameters.SCENE_MODE_PORTRAIT); break; } } } */ /* * zoom can impact view angle. we should set it to 0 if it's not */ if (mCameraParams.isZoomSupported()) { int zoom = mCameraParams.getZoom(); if (zoom != 0) { if (BuildConfig.DEBUG) Log.d(TAG, "getViewAngle: camera zoom = " + zoom + ", forcing to zero"); mCameraParams.setZoom(0); } } /* * leave the frame rate set to default */ mCamera.setParameters(mCameraParams); /* int[] fpsRange = new int[2]; mCameraParams.getPreviewFpsRange(fpsRange); String previewFacts = VIDEO_DIMENSIONS[mQualityPref][0] + "x" + VIDEO_DIMENSIONS[mQualityPref][1]; if (fpsRange[0] == fpsRange[1]) { previewFacts += " @" + (fpsRange[0] / 1000.0) + "fps"; } else { previewFacts += " @[" + (fpsRange[0] / 1000.0) + " - " + (fpsRange[1] / 1000.0) + "] fps"; } TextView text = (TextView) findViewById(R.id.cameraParams_text); text.setText(previewFacts); */ if (mNaturalOrientation == Configuration.ORIENTATION_PORTRAIT) { if (((info.facing == Camera.CameraInfo.CAMERA_FACING_BACK) && (mLandscapeOrientation == mCameraOrientation)) || ((info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) && (mLandscapeOrientation != mCameraOrientation))) { mCamera.setDisplayOrientation(180); mCameraOrientation = (mCameraOrientation + 180) % 360; } } if (mOrientationEventListener == null) { mOrientationEventListener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL) { @Override public void onOrientationChanged(int deviceOrientation) { if (deviceOrientation == ORIENTATION_UNKNOWN) return; handleOrientationChanged(deviceOrientation); } }; if (mOrientationEventListener.canDetectOrientation()) { mOrientationEventListener.enable(); } } Runnable forceOrientationCalcRunnable = new Runnable() { public void run() { final Handler handler = new Handler(); handler.postDelayed(new Runnable() { public void run() { int deviceOrientation = mCurrDeviceOrientation; mCurrDeviceOrientation = -1; handleOrientationChanged(deviceOrientation); } }, 100); } }; runOnUiThread(forceOrientationCalcRunnable); return true; }