List of usage examples for android.hardware Camera setParameters
public void setParameters(Parameters params)
From source file:com.TaxiDriver.jy.CameraPreview.java
public void switchCamera(Camera camera) { setCamera(camera);/*w w w . j a v a 2 s .co m*/ try { camera.setPreviewDisplay(mHolder); } catch (IOException exception) { Log.e(TAG, "IOException caused by setPreviewDisplay()", exception); } Camera.Parameters parameters = camera.getParameters(); parameters.setPreviewSize(mPreviewSize.width, mPreviewSize.height); requestLayout(); camera.setParameters(parameters); }
From source file:org.deviceconnect.android.deviceplugin.host.camera.CameraOverlay.java
private void setRequestedPictureSize(final Camera camera) { HostDeviceRecorder.PictureSize currentSize = mPictureSize; if (camera != null && currentSize != null) { Camera.Parameters params = camera.getParameters(); params.setPictureSize(currentSize.getWidth(), currentSize.getHeight()); camera.setParameters(params); }/*from w ww . j a v a 2 s . co m*/ }
From source file:org.deviceconnect.android.deviceplugin.host.camera.CameraOverlay.java
private void setRequestedPreviewSize(final Camera camera) { HostDeviceRecorder.PictureSize currentSize = mPreviewSize; if (camera != null && currentSize != null) { Camera.Parameters params = camera.getParameters(); params.setPreviewSize(currentSize.getWidth(), currentSize.getHeight()); camera.setParameters(params); }/*from www . j a v a2 s .c o m*/ }
From source file:com.example.android.animationsdemo.CameraActivity.java
private void startFocus(int x, int y) { if (mCamera != null) { mCamera.cancelAutoFocus();//ww w. j a va 2 s. c o m Rect focusRect = calculateTapArea(x, y); Camera.Parameters parameters = mCamera.getParameters(); if (parameters.getFocusMode() != Camera.Parameters.FOCUS_MODE_AUTO) { parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); } if (parameters.getMaxNumFocusAreas() > 0) { List<Camera.Area> mylist = new ArrayList<Camera.Area>(); mylist.add(new Camera.Area(focusRect, 1000)); parameters.setFocusAreas(mylist); } try { mCamera.cancelAutoFocus(); mCamera.setParameters(parameters); mCamera.startPreview(); mCamera.autoFocus(new Camera.AutoFocusCallback() { @Override public void onAutoFocus(boolean success, Camera camera) { if (camera.getParameters() .getFocusMode() != Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE) { Camera.Parameters parameters = camera.getParameters(); parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); if (parameters.getMaxNumFocusAreas() > 0) { parameters.setFocusAreas(null); } camera.setParameters(parameters); camera.startPreview(); } } }); } catch (Exception e) { DKLog.e(TAG, Trace.getCurrentMethod() + e.toString()); } } }
From source file:Main.java
public static void setFocusMode(Camera mCamera, Context item, int type) { Camera.Parameters params = mCamera.getParameters(); List<String> FocusModes = params.getSupportedFocusModes(); switch (type) { case 0:/*from w ww.java 2s .c om*/ if (FocusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) params.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); else Toast.makeText(item, "Auto Mode not supported", Toast.LENGTH_SHORT).show(); break; case 1: if (FocusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO); else Toast.makeText(item, "Continuous Mode not supported", Toast.LENGTH_SHORT).show(); break; case 2: if (FocusModes.contains(Camera.Parameters.FOCUS_MODE_EDOF)) params.setFocusMode(Camera.Parameters.FOCUS_MODE_EDOF); else Toast.makeText(item, "EDOF Mode not supported", Toast.LENGTH_SHORT).show(); break; case 3: if (FocusModes.contains(Camera.Parameters.FOCUS_MODE_FIXED)) params.setFocusMode(Camera.Parameters.FOCUS_MODE_FIXED); else Toast.makeText(item, "Fixed Mode not supported", Toast.LENGTH_SHORT).show(); break; case 4: if (FocusModes.contains(Camera.Parameters.FOCUS_MODE_INFINITY)) params.setFocusMode(Camera.Parameters.FOCUS_MODE_INFINITY); else Toast.makeText(item, "Infinity Mode not supported", Toast.LENGTH_SHORT).show(); break; case 5: if (FocusModes.contains(Camera.Parameters.FOCUS_MODE_MACRO)) params.setFocusMode(Camera.Parameters.FOCUS_MODE_MACRO); else Toast.makeText(item, "Macro Mode not supported", Toast.LENGTH_SHORT).show(); break; } mCamera.setParameters(params); }
From source file:com.dngames.mobilewebcam.PhotoSettings.java
public void SetCameraParameters(Camera cam, boolean configure) { Camera.Parameters params = cam.getParameters(); if (params != null) { SetCameraParameters(params, configure); try {//from ww w .j ava2 s . c om cam.setParameters(params); } catch (RuntimeException e) { e.printStackTrace(); } } }
From source file:com.android.launcher3.Utilities.java
public static void turnOnFlashLight(Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { CameraManager camManager = (CameraManager) context.getApplicationContext() .getSystemService(Context.CAMERA_SERVICE); String cameraId = null;/*from ww w . j ava 2s.c om*/ try { cameraId = camManager.getCameraIdList()[0]; camManager.setTorchMode(cameraId, true); isFlashLightOn = true; } catch (CameraAccessException e) { isFlashLightOn = false; e.printStackTrace(); } } else { try { if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)) { Camera cam = Camera.open(); Camera.Parameters p = cam.getParameters(); p.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH); cam.setParameters(p); cam.startPreview(); isFlashLightOn = true; } } catch (Exception e) { e.printStackTrace(); isFlashLightOn = false; } } }
From source file:com.csusm.twinder.Fragment.QRScanFragment.java
@Nullable @Override/* w w w .j a v a 2s .com*/ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_scan, container, false); view.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { Camera camera = mCameraSource.getCamera(); if (camera != null) { camera.cancelAutoFocus(); Rect focusRect = calculateTapArea((int) event.getX(), (int) event.getY(), 1f); Camera.Parameters parameters = camera.getParameters(); parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); if (parameters.getMaxNumFocusAreas() > 0) { List<Camera.Area> mylist = new ArrayList<Camera.Area>(); mylist.add(new Camera.Area(focusRect, 1000)); parameters.setFocusAreas(mylist); } //camera.setParameters(parameters); camera.autoFocus(new Camera.AutoFocusCallback() { @Override public void onAutoFocus(boolean success, Camera camera) { camera.cancelAutoFocus(); Camera.Parameters params = camera.getParameters(); if (params.getFocusMode() != Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE) { params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); camera.setParameters(params); } } }); } return true; } }); return view; }
From source file:com.jasompeter.openalpr.CameraActivity.java
public void setCorrectOrientation(Camera camera) { int displayRotation = getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (displayRotation) { case Surface.ROTATION_0: degrees = 0;//from w w w . j a va 2 s .c o m break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } Camera.CameraInfo cameraInfo = getCurrentCameraInfo(); int resultDegrees; if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { resultDegrees = (cameraInfo.orientation + degrees) % 360; resultDegrees = (360 - resultDegrees) % 360; } else { resultDegrees = (cameraInfo.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(resultDegrees); Camera.Parameters parameters = camera.getParameters(); parameters.setRotation(resultDegrees); camera.setParameters(parameters); }
From source file:com.gelakinetic.selfr.CameraActivity.java
/** * A safe way to get an instance of the Camera object. Also sets up picture size & focus type * * @param cameraType Camera.CameraInfo.CAMERA_FACING_FRONT or * Camera.CameraInfo.CAMERA_FACING_BACK * @return A Camera object if it was created, or null *//*from ww w .j a va 2 s . co m*/ @Nullable private static Camera getCameraInstance(int cameraType) { Camera camera = null; try { Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); /* Scan through all the cameras for one of the specified type */ for (int camIdx = 0; camIdx < Camera.getNumberOfCameras(); camIdx++) { Camera.getCameraInfo(camIdx, cameraInfo); if (cameraInfo.facing == cameraType) { try { /* Open the camera, get default parameters */ camera = Camera.open(camIdx); Camera.Parameters parameters = camera.getParameters(); /* Set the image to native resolution */ List<Camera.Size> sizes = parameters.getSupportedPictureSizes(); Camera.Size nativeSize = null; int maxHeight = Integer.MIN_VALUE; for (Camera.Size size : sizes) { if (size.height > maxHeight) { maxHeight = size.height; nativeSize = size; } } if (nativeSize != null) { parameters.setPictureSize(nativeSize.width, nativeSize.height); } /* Set auto-focus, if we can */ List<String> focusModes = parameters.getSupportedFocusModes(); if (focusModes != null && focusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) { parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); } /* Set the parameters */ camera.setParameters(parameters); } catch (RuntimeException e) { /* Eat it */ } } } } catch (Exception e) { /* Camera is not available (in use or does not exist) */ } return camera; /* returns null if camera is unavailable */ }