Java Code Examples for android.hardware.Camera#stopPreview()
The following examples show how to use
android.hardware.Camera#stopPreview() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CameraManager.java From StarBarcode with Apache License 2.0 | 6 votes |
/** * 停止预览 */ @Override public void stopPreview() { if (isOpenCamera() && previewing) { try { Camera theCamera = mCamera.getCamera(); if (focusManager != null) { focusManager.stop(); focusManager = null; } theCamera.setOneShotPreviewCallback(null); theCamera.stopPreview(); previewing = false; } catch (Exception e) { e.printStackTrace(); } } }
Example 2
Source File: CameraTester.java From PermissionAgent with Apache License 2.0 | 6 votes |
@Override public boolean test() throws Throwable { Camera camera = null; try { camera = Camera.open(); Camera.Parameters parameters = camera.getParameters(); camera.setParameters(parameters); camera.setPreviewCallback(PREVIEW_CALLBACK); camera.startPreview(); return true; } catch (Throwable e) { PackageManager packageManager = mContext.getPackageManager(); return !packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA); } finally { if (camera != null) { camera.stopPreview(); camera.setPreviewCallback(null); camera.release(); } } }
Example 3
Source File: CameraTester.java From PermissionAgent with Apache License 2.0 | 6 votes |
@Override public boolean test() throws Throwable { Camera camera = null; try { camera = Camera.open(); Camera.Parameters parameters = camera.getParameters(); camera.setParameters(parameters); camera.setPreviewCallback(PREVIEW_CALLBACK); camera.startPreview(); return true; } catch (Throwable e) { PackageManager packageManager = mContext.getPackageManager(); return !packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA); } finally { if (camera != null) { camera.stopPreview(); camera.setPreviewCallback(null); camera.release(); } } }
Example 4
Source File: CodeScanner.java From code-scanner with MIT License | 6 votes |
private void stopPreviewInternal(final boolean internal) { try { final DecoderWrapper decoderWrapper = mDecoderWrapper; if (decoderWrapper != null) { final Camera camera = decoderWrapper.getCamera(); camera.cancelAutoFocus(); final Parameters parameters = camera.getParameters(); if (!internal && decoderWrapper.isFlashSupported() && mFlashEnabled) { Utils.setFlashMode(parameters, Parameters.FLASH_MODE_OFF); } camera.setParameters(parameters); camera.setPreviewCallback(null); camera.stopPreview(); } } catch (final Exception ignored) { } mStoppingPreview = false; mPreviewActive = false; mSafeAutoFocusing = false; mSafeAutoFocusAttemptsCount = 0; }
Example 5
Source File: CameraManager.java From Android with MIT License | 6 votes |
/** * Set the camera to camera (turn off the old camera, turn on the new camera) * * @param mCamera */ public Camera setChangeParameters(Activity activity, Camera mCamera, SurfaceHolder viewHolder) { if (Camera.getNumberOfCameras() <= 1) { return null; } try { mCamera.stopPreview(); mCamera.setPreviewCallback(null); mCamera.release(); cameraPosition = cameraPosition == 1 ? 0 : 1; Camera mNewCamera = getCameraInstance(cameraPosition); setParametersCamera(activity, mNewCamera); mNewCamera.setPreviewDisplay(viewHolder); mNewCamera.startPreview(); return mNewCamera; } catch (Exception e) { e.printStackTrace(); } return null; }
Example 6
Source File: CameraTest.java From AndPermission with Apache License 2.0 | 6 votes |
@Override public boolean test() throws Throwable { Camera camera = null; try { int cameraCount = Camera.getNumberOfCameras(); if (cameraCount <= 0) return true; camera = Camera.open(cameraCount - 1); Camera.Parameters parameters = camera.getParameters(); camera.setParameters(parameters); camera.setPreviewCallback(PREVIEW_CALLBACK); camera.startPreview(); return true; } catch (Throwable e) { PackageManager packageManager = mContext.getPackageManager(); return !packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA); } finally { if (camera != null) { camera.stopPreview(); camera.setPreviewCallback(null); camera.release(); } } }
Example 7
Source File: CameraUtils.java From DevUtils with Apache License 2.0 | 5 votes |
/** * 释放摄像头资源 * @param camera {@link android.hardware.Camera} */ public static void freeCameraResource(final Camera camera) { try { if (camera != null) { camera.setPreviewCallback(null); camera.stopPreview(); camera.lock(); camera.release(); } } catch (Exception e) { LogPrintUtils.eTag(TAG, e, "freeCameraResource"); } }
Example 8
Source File: RCTCameraModule.java From react-native-camera-face-detector with MIT License | 5 votes |
@ReactMethod public void stopPreview(ReadableMap options) { RCTCamera instance = RCTCamera.getInstance(); if (instance == null) return; Camera camera = instance.acquireCameraInstance(options.getInt("type")); if (camera == null) return; camera.stopPreview(); }
Example 9
Source File: CameraUtils.java From jitsi-android with Apache License 2.0 | 5 votes |
/** * Releases the camera. * @param camera the camera to release. */ public static void releaseCamera(final Camera camera) { camera.stopPreview(); surfaceProvider.onObjectReleased(); camera.release(); }
Example 10
Source File: ICamera.java From MegviiFacepp-Android-SDK with Apache License 2.0 | 4 votes |
public static ArrayList<HashMap<String, Integer>> getCameraPreviewSize( int cameraId) { ArrayList<HashMap<String, Integer>> size = new ArrayList<HashMap<String, Integer>>(); Camera camera = null; try { camera = Camera.open(cameraId); if (camera == null) camera = Camera.open(0); List<Camera.Size> allSupportedSize = camera.getParameters() .getSupportedPreviewSizes(); for (Camera.Size tmpSize : allSupportedSize) { if (tmpSize.width > tmpSize.height) { HashMap<String, Integer> map = new HashMap<String, Integer>(); map.put("width", tmpSize.width); map.put("height", tmpSize.height); if (tmpSize.width==640&&tmpSize.height==480){ size.add(map); } if (tmpSize.width==960&&tmpSize.height==540){ size.add(map); } if (tmpSize.width==1280&&tmpSize.height==720){ size.add(map); } if (tmpSize.width==1920&&tmpSize.height==1080){ size.add(map); } } } } catch (Exception e) { e.printStackTrace(); } finally { if (camera != null) { camera.stopPreview(); camera.setPreviewCallback(null); camera.release(); camera = null; } } return size; }