/** Returns the rotation matrix describing the devices rotation as per <a href= * "http://developer.android.com/reference/android/hardware/SensorManager.html#getRotationMatrix(float[], float[], float[], float[])" * >SensorManager#getRotationMatrix(float[], float[], float[], float[])</a>. Does not manipulate the matrix if the platform * does not have an accelerometer and compass, or a rotation vector sensor. * @param matrix */ public void getRotationMatrix (float[] matrix) { if (rotationVectorAvailable) SensorManager.getRotationMatrixFromVector(matrix, rotationVectorValues); else // compass + accelerometer SensorManager.getRotationMatrix(matrix, null, accelerometerValues, magneticFieldValues); }
Camera cam = Camera.open(); Parameters p = cam.getParameters(); p.setFlashMode(Parameters.FLASH_MODE_TORCH); cam.setParameters(p); cam.startPreview();
@Override public void onAutoFocus(boolean success, Camera camera) { Camera.Parameters params = camera.getParameters(); params.setFocusMode(currentFocusMode); camera.setParameters(params); } });
private int findBackCamera(){ 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_BACK ) { return camIdx; } } return -1; }
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { Camera.Parameters parameters = camera.getParameters(); List<Camera.Size> previewSizes = parameters.getSupportedPreviewSizes(); // You need to choose the most appropriate previewSize for your app Camera.Size previewSize = // .... select one of previewSizes here parameters.setPreviewSize(previewSize.width, previewSize.height); camera.setParameters(parameters); camera.startPreview(); }
@Override public void onPreviewFrame(final byte[] data, final Camera camera) { final Size previewSize = camera.getParameters().getPreviewSize(); onPreviewFrame(data, previewSize.width, previewSize.height); }
/** * This rewrites {@link #mCameraId} and {@link #mCameraInfo}. */ private void chooseCamera() { for (int i = 0, count = Camera.getNumberOfCameras(); i < count; i++) { Camera.getCameraInfo(i, mCameraInfo); if (mCameraInfo.facing == mFacing) { mCameraId = i; return; } } mCameraId = INVALID_CAMERA_ID; }
private Camera.Parameters getDefaultCameraParameters() { Camera.Parameters parameters = camera.getParameters(); if (defaultParameters == null) { defaultParameters = parameters.flatten(); } else { parameters.unflatten(defaultParameters); } return parameters; }
Camera.Parameters parameters = mCamera.getParameters(); parameters.setPreviewSize(mPreviewSize.width, mPreviewSize.height); mCamera.setParameters(parameters); mCamera.startPreview();
//set camera to continually auto-focus Camera.Parameters params = c.getParameters(); //*EDIT*//params.setFocusMode("continuous-picture"); //It is better to use defined constraints as opposed to String, thanks to AbdelHady params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); c.setParameters(params);
private void updateOrientation () { if (rotationVectorAvailable){ SensorManager.getRotationMatrixFromVector(R, rotationVectorValues); } else if (!SensorManager.getRotationMatrix(R, null, accelerometerValues, magneticFieldValues)) { return; // compass + accelerometer in free fall } SensorManager.getOrientation(R, orientation); azimuth = (float)Math.toDegrees(orientation[0]); pitch = (float)Math.toDegrees(orientation[1]); roll = (float)Math.toDegrees(orientation[2]); }
/** * Allows test cases to invoke the preview callback, to simulate a frame of camera data. * * @param data byte buffer of simulated camera data */ public void invokePreviewCallback(byte[] data) { if (previewCallback != null) { previewCallback.onPreviewFrame(data, realCamera); } }
@Implementation protected void takePicture( Camera.ShutterCallback shutter, Camera.PictureCallback raw, Camera.PictureCallback jpeg) { if (shutter != null) { shutter.onShutter(); } if (raw != null) { raw.onPictureTaken(new byte[0], realCamera); } if (jpeg != null) { jpeg.onPictureTaken(new byte[0], realCamera); } }
/** Propagates the {@code event} to all registered listeners. */ public void sendSensorEventToListeners(SensorEvent event) { for (SensorEventListener listener : listeners) { listener.onSensorChanged(event); } }
private int findFrontCamera(){ 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 ) { return camIdx; } } return -1; }
private void updateOrientation () { if (rotationVectorAvailable){ SensorManager.getRotationMatrixFromVector(R, rotationVectorValues); } else if (!SensorManager.getRotationMatrix(R, null, accelerometerValues, magneticFieldValues)) { return; // compass + accelerometer in free fall } SensorManager.getOrientation(R, orientation); azimuth = (float)Math.toDegrees(orientation[0]); pitch = (float)Math.toDegrees(orientation[1]); roll = (float)Math.toDegrees(orientation[2]); }
/** Returns the rotation matrix describing the devices rotation as per <a href= * "http://developer.android.com/reference/android/hardware/SensorManager.html#getRotationMatrix(float[], float[], float[], float[])" * >SensorManager#getRotationMatrix(float[], float[], float[], float[])</a>. Does not manipulate the matrix if the platform * does not have an accelerometer and compass, or a rotation vector sensor. * @param matrix */ public void getRotationMatrix (float[] matrix) { if (rotationVectorAvailable) SensorManager.getRotationMatrixFromVector(matrix, rotationVectorValues); else // compass + accelerometer SensorManager.getRotationMatrix(matrix, null, accelerometerValues, magneticFieldValues); }
private int findBackCamera() { 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_BACK) { return camIdx; } } return -1; }
private int findFrontCamera() { 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) { return camIdx; } } return -1; }
/** Favor back-facing camera by default. If none exists, fallback to whatever camera is available **/ public static int getDefaultCameraId() { int numberOfCameras = Camera.getNumberOfCameras(); Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); int defaultCameraId = -1; for (int i = 0; i < numberOfCameras; i++) { defaultCameraId = i; Camera.getCameraInfo(i, cameraInfo); if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) { return i; } } return defaultCameraId; }