android.hardware.Camera.Parameters Java Examples
The following examples show how to use
android.hardware.Camera.Parameters.
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: CameraView.java From LLApp with Apache License 2.0 | 6 votes |
/** * 设置相机缩放级别 * @param zoom */ @Override public void setZoom(int zoom){ if(mCamera==null) return; Parameters parameters; //注意此处为录像模式下的setZoom方式。在Camera.unlock之后,调用getParameters方法会引起android框架底层的异常 //stackoverflow上看到的解释是由于多线程同时访问Camera导致的冲突,所以在此使用录像前保存的mParameters。 if(mParameters!=null) parameters=mParameters; else { parameters=mCamera.getParameters(); } if(!parameters.isZoomSupported()) return; parameters.setZoom(zoom); mCamera.setParameters(parameters); mZoom=zoom; }
Example #2
Source File: LegacyMetadataMapper.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Convert the ae antibanding mode from api1 into api2. * * @param mode the api1 mode, {@code null} is allowed and will return {@code -1}. * * @return The api2 value, or {@code -1} by default if conversion failed */ private static int convertAntiBandingMode(String mode) { if (mode == null) { return -1; } switch (mode) { case Camera.Parameters.ANTIBANDING_OFF: { return CONTROL_AE_ANTIBANDING_MODE_OFF; } case Camera.Parameters.ANTIBANDING_50HZ: { return CONTROL_AE_ANTIBANDING_MODE_50HZ; } case Camera.Parameters.ANTIBANDING_60HZ: { return CONTROL_AE_ANTIBANDING_MODE_60HZ; } case Camera.Parameters.ANTIBANDING_AUTO: { return CONTROL_AE_ANTIBANDING_MODE_AUTO; } default: { Log.w(TAG, "convertAntiBandingMode - Unknown antibanding mode " + mode); return -1; } } }
Example #3
Source File: CameraView.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
@Override public void onOrientationChanged(int orientation) { if (camera.isPresent() && orientation != ORIENTATION_UNKNOWN) { int newOutputOrientation = getCameraPictureRotation(orientation); if (newOutputOrientation != outputOrientation) { outputOrientation = newOutputOrientation; Camera.Parameters params = camera.get().getParameters(); params.setRotation(outputOrientation); try { camera.get().setParameters(params); } catch (Exception e) { Log.e(TAG, "Exception updating camera parameters in orientation change", e); } } } }
Example #4
Source File: LegacyMetadataMapper.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private static void mapStatistics(CameraMetadataNative m, Parameters p) { /* * statistics.info.availableFaceDetectModes */ int[] fdModes; if (p.getMaxNumDetectedFaces() > 0) { fdModes = new int[] { STATISTICS_FACE_DETECT_MODE_OFF, STATISTICS_FACE_DETECT_MODE_SIMPLE // FULL is never-listed, since we have no way to query it statically }; } else { fdModes = new int[] { STATISTICS_FACE_DETECT_MODE_OFF }; } m.set(STATISTICS_INFO_AVAILABLE_FACE_DETECT_MODES, fdModes); /* * statistics.info.maxFaceCount */ m.set(STATISTICS_INFO_MAX_FACE_COUNT, p.getMaxNumDetectedFaces()); }
Example #5
Source File: CameraSurfaceView.java From Android-Screen-to-Face-Distance-Measurement with MIT License | 6 votes |
public void setCamera(final Camera camera) { mCamera = camera; if (mCamera != null) { requestLayout(); Camera.Parameters params = mCamera.getParameters(); camera.setDisplayOrientation(90); List<String> focusModes = params.getSupportedFocusModes(); if (focusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) { // set the focus mode params.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); // set Camera parameters mCamera.setParameters(params); } } }
Example #6
Source File: Camera1Handler.java From Augendiagnose with GNU General Public License v2.0 | 6 votes |
/** * Get the best preview size. * * @param aspectRatio The aspect ratio of the picture. * @param parameters The camera parameters. * @return The best preview size. */ @Nullable private static Camera.Size getBestPreviewSize(final float aspectRatio, @NonNull final Camera.Parameters parameters) { Camera.Size result = null; float bestAspectRatioDifference = 0; for (Camera.Size size : parameters.getSupportedPreviewSizes()) { float newAspectRatioDifference = Math.abs(((float) size.width) / size.height - aspectRatio); if (result == null) { result = size; bestAspectRatioDifference = newAspectRatioDifference; } else { if ((newAspectRatioDifference < bestAspectRatioDifference - 0.01f) // MAGIC_NUMBER || (size.width > result.width && newAspectRatioDifference < bestAspectRatioDifference + 0.01f)) { // MAGIC_NUMBER result = size; bestAspectRatioDifference = newAspectRatioDifference; } } } return result; }
Example #7
Source File: LegacyRequestMapper.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private static String convertAwbModeToLegacy(int mode) { switch (mode) { case CONTROL_AWB_MODE_AUTO: return Camera.Parameters.WHITE_BALANCE_AUTO; case CONTROL_AWB_MODE_INCANDESCENT: return Camera.Parameters.WHITE_BALANCE_INCANDESCENT; case CONTROL_AWB_MODE_FLUORESCENT: return Camera.Parameters.WHITE_BALANCE_FLUORESCENT; case CONTROL_AWB_MODE_WARM_FLUORESCENT: return Camera.Parameters.WHITE_BALANCE_WARM_FLUORESCENT; case CONTROL_AWB_MODE_DAYLIGHT: return Camera.Parameters.WHITE_BALANCE_DAYLIGHT; case CONTROL_AWB_MODE_CLOUDY_DAYLIGHT: return Camera.Parameters.WHITE_BALANCE_CLOUDY_DAYLIGHT; case CONTROL_AWB_MODE_TWILIGHT: return Camera.Parameters.WHITE_BALANCE_TWILIGHT; case CONTROL_AWB_MODE_SHADE: return Parameters.WHITE_BALANCE_SHADE; default: Log.w(TAG, "convertAwbModeToLegacy - unrecognized control.awbMode" + mode); return Camera.Parameters.WHITE_BALANCE_AUTO; } }
Example #8
Source File: LegacyResultMapper.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private static void mapAf(CameraMetadataNative m, Rect activeArray, ZoomData zoomData, Camera.Parameters p) { // control.afMode m.set(CaptureResult.CONTROL_AF_MODE, convertLegacyAfMode(p.getFocusMode())); // control.afRegions if (p.getMaxNumFocusAreas() > 0) { if (DEBUG) { String focusAreas = p.get("focus-areas"); Log.v(TAG, "mapAe - parameter dump; focus-areas: " + focusAreas); } MeteringRectangle[] meteringRectArray = getMeteringRectangles(activeArray, zoomData, p.getFocusAreas(), "AF"); m.set(CONTROL_AF_REGIONS, meteringRectArray); } }
Example #9
Source File: Camera1Handler.java From Augendiagnose with GNU General Public License v2.0 | 6 votes |
/** * Get the biggest possible picture size. * * @param parameters The camera parameters. * @return The biggest picture size. */ @Nullable private static Camera.Size getBiggestPictureSize(@NonNull final Camera.Parameters parameters) { Camera.Size result = null; for (Camera.Size size : parameters.getSupportedPictureSizes()) { if (result == null) { result = size; } else { int resultSize = Math.min(result.width, result.height); int newSize = Math.min(size.width, size.height); if (newSize > resultSize || (newSize == resultSize && size.width > result.width)) { result = size; } } } return result; }
Example #10
Source File: VideoStream.java From spydroid-ipcamera with GNU General Public License v3.0 | 6 votes |
protected synchronized void updateCamera() throws RuntimeException { if (mPreviewStarted) { mPreviewStarted = false; mCamera.stopPreview(); } Parameters parameters = mCamera.getParameters(); mQuality = VideoQuality.determineClosestSupportedResolution(parameters, mQuality); int[] max = VideoQuality.determineMaximumSupportedFramerate(parameters); parameters.setPreviewFormat(mCameraImageFormat); parameters.setPreviewSize(mQuality.resX, mQuality.resY); parameters.setPreviewFpsRange(max[0], max[1]); try { mCamera.setParameters(parameters); mCamera.setDisplayOrientation(mOrientation); mCamera.startPreview(); mPreviewStarted = true; } catch (RuntimeException e) { destroyCamera(); throw e; } }
Example #11
Source File: CameraView.java From zom-android-matrix with Apache License 2.0 | 6 votes |
private void startPreview(SurfaceHolder holder) { try { Parameters params = camera.getParameters(); if (params.getSupportedFocusModes().contains( Parameters.FOCUS_MODE_AUTO)) { params.setFocusMode(Parameters.FOCUS_MODE_AUTO); } List<Size> previewSizes = camera.getParameters().getSupportedPreviewSizes(); List<Size> pictureSizes = camera.getParameters().getSupportedPictureSizes(); params.setPreviewSize(previewSizes.get(previewSizes.size()-2).width,previewSizes.get(previewSizes.size()-2).height); params.setPictureSize(pictureSizes.get(pictureSizes.size()-2).width,pictureSizes.get(pictureSizes.size()-2).height); camera.setParameters(params); camera.setPreviewDisplay(holder); camera.startPreview(); previewConsumer.start(camera); } catch(IOException e) { Log.e(TAG, "Error starting camera preview", e); } }
Example #12
Source File: CameraSource.java From mlkit-material-android with Apache License 2.0 | 6 votes |
/** * Selects the most suitable preview frames per second range. * * @param camera the camera to select a frames per second range from * @return the selected preview frames per second range */ private static int[] selectPreviewFpsRange(Camera camera) { // The camera API uses integers scaled by a factor of 1000 instead of floating-point frame // rates. int desiredPreviewFpsScaled = (int) (REQUESTED_CAMERA_FPS * 1000f); // The method for selecting the best range is to minimize the sum of the differences between // the desired value and the upper and lower bounds of the range. This may select a range // that the desired value is outside of, but this is often preferred. For example, if the // desired frame rate is 29.97, the range (30, 30) is probably more desirable than the // range (15, 30). int[] selectedFpsRange = null; int minDiff = Integer.MAX_VALUE; for (int[] range : camera.getParameters().getSupportedPreviewFpsRange()) { int deltaMin = desiredPreviewFpsScaled - range[Camera.Parameters.PREVIEW_FPS_MIN_INDEX]; int deltaMax = desiredPreviewFpsScaled - range[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]; int diff = Math.abs(deltaMin) + Math.abs(deltaMax); if (diff < minDiff) { selectedFpsRange = range; minDiff = diff; } } return selectedFpsRange; }
Example #13
Source File: AndroidCameraAgentImpl.java From Camera2 with Apache License 2.0 | 6 votes |
@Deprecated @Override public void setParameters(final Parameters params) { if (params == null) { Log.v(TAG, "null parameters in setParameters()"); return; } final String flattenedParameters = params.flatten(); try { mDispatchThread.runJob(new Runnable() { @Override public void run() { mCameraState.waitForStates(AndroidCameraStateHolder.CAMERA_IDLE | AndroidCameraStateHolder.CAMERA_UNLOCKED); mCameraHandler.obtainMessage(CameraActions.SET_PARAMETERS, flattenedParameters) .sendToTarget(); } }); } catch (final RuntimeException ex) { mCameraAgent.getCameraExceptionHandler().onDispatchThreadException(ex); } }
Example #14
Source File: CameraViewProxy.java From Ti-Android-CameraView with MIT License | 6 votes |
/** * Function to determine if flash support is available * @return Boolean Flash Support */ private boolean hasFlash(){ Camera cam = ((CameraView) view).currentCameraInstance(); Parameters params = cam.getParameters(); List<String> flashModes = params.getSupportedFlashModes(); if(flashModes == null) { return false; } for(String flashMode : flashModes) { if(Parameters.FLASH_MODE_ON.equals(flashMode)) { return true; } } return false; }
Example #15
Source File: CameraSource.java From fast_qr_reader_view with MIT License | 6 votes |
/** * Selects the most suitable preview frames per second range, given the desired frames per second. * * @param camera the camera to select a frames per second range from * @param desiredPreviewFps the desired frames per second for the camera preview frames * @return the selected preview frames per second range */ @SuppressLint("InlinedApi") private static int[] selectPreviewFpsRange(Camera camera, float desiredPreviewFps) { // The camera API uses integers scaled by a factor of 1000 instead of floating-point frame // rates. int desiredPreviewFpsScaled = (int) (desiredPreviewFps * 1000.0f); // The method for selecting the best range is to minimize the sum of the differences between // the desired value and the upper and lower bounds of the range. This may select a range // that the desired value is outside of, but this is often preferred. For example, if the // desired frame rate is 29.97, the range (30, 30) is probably more desirable than the // range (15, 30). int[] selectedFpsRange = null; int minDiff = Integer.MAX_VALUE; List<int[]> previewFpsRangeList = camera.getParameters().getSupportedPreviewFpsRange(); for (int[] range : previewFpsRangeList) { int deltaMin = desiredPreviewFpsScaled - range[Camera.Parameters.PREVIEW_FPS_MIN_INDEX]; int deltaMax = desiredPreviewFpsScaled - range[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]; int diff = Math.abs(deltaMin) + Math.abs(deltaMax); if (diff < minDiff) { selectedFpsRange = range; minDiff = diff; } } return selectedFpsRange; }
Example #16
Source File: CameraEncoder.java From kickflip-android-sdk with Apache License 2.0 | 6 votes |
/** * Attempts to find a preview size that matches the provided width and height (which * specify the dimensions of the encoded video). If it fails to find a match it just * uses the default preview size. * <p/> * TODO: should do a best-fit match. */ private static void choosePreviewSize(Camera.Parameters parms, int width, int height) { // We should make sure that the requested MPEG size is less than the preferred // size, and has the same aspect ratio. Camera.Size ppsfv = parms.getPreferredPreviewSizeForVideo(); if (ppsfv != null && VERBOSE) { Log.d(TAG, "Camera preferred preview size for video is " + ppsfv.width + "x" + ppsfv.height); } for (Camera.Size size : parms.getSupportedPreviewSizes()) { if (size.width == width && size.height == height) { parms.setPreviewSize(width, height); return; } } Log.w(TAG, "Unable to set preview size to " + width + "x" + height); if (ppsfv != null) { parms.setPreviewSize(ppsfv.width, ppsfv.height); } // else use whatever the default size is }
Example #17
Source File: RecorderVideoActivity.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 6 votes |
@SuppressLint("NewApi") private boolean initCamera() { try { if (frontCamera == 0) { mCamera = Camera.open(CameraInfo.CAMERA_FACING_BACK); } else { mCamera = Camera.open(CameraInfo.CAMERA_FACING_FRONT); } Camera.Parameters camParams = mCamera.getParameters(); mCamera.lock(); mSurfaceHolder = mVideoView.getHolder(); mSurfaceHolder.addCallback(this); mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); mCamera.setDisplayOrientation(90); } catch (RuntimeException ex) { EMLog.e("video", "init Camera fail " + ex.getMessage()); return false; } return true; }
Example #18
Source File: FaceScanner.java From Eye-blink-detector with MIT License | 6 votes |
/** * Set the flash on or off * * @param b desired flash state * @return <code>true</code> if successful */ public boolean setFlashOn(boolean b) { if (mCamera != null) { try { Camera.Parameters params = mCamera.getParameters(); params.setFlashMode(b ? Parameters.FLASH_MODE_TORCH : Parameters.FLASH_MODE_OFF); mCamera.setParameters(params); return true; } catch (RuntimeException e) { Log.w(TAG, "Could not set flash mode: " + e); } } return false; }
Example #19
Source File: CodeScanner.java From code-scanner with MIT License | 6 votes |
/** * Set current zoom value (between {@code 0} and {@link Parameters#getMaxZoom()}, if larger, * max zoom value will be set */ public void setZoom(final int zoom) { if (zoom < 0) { throw new IllegalArgumentException("Zoom value must be greater than or equal to zero"); } synchronized (mInitializeLock) { if (zoom != mZoom) { mZoom = zoom; if (mInitialized) { final DecoderWrapper decoderWrapper = mDecoderWrapper; if (decoderWrapper != null) { final Camera camera = decoderWrapper.getCamera(); final Parameters parameters = camera.getParameters(); Utils.setZoom(parameters, zoom); camera.setParameters(parameters); } } } } mZoom = zoom; }
Example #20
Source File: CodeScanner.java From code-scanner with MIT License | 6 votes |
private void setFlashEnabledInternal(final boolean flashEnabled) { try { final DecoderWrapper decoderWrapper = mDecoderWrapper; if (decoderWrapper != null) { final Camera camera = decoderWrapper.getCamera(); final Parameters parameters = camera.getParameters(); if (parameters == null) { return; } if (flashEnabled) { Utils.setFlashMode(parameters, Parameters.FLASH_MODE_TORCH); } else { Utils.setFlashMode(parameters, Parameters.FLASH_MODE_OFF); } camera.setParameters(parameters); } } catch (final Exception ignored) { } }
Example #21
Source File: AndroidCameraAgentImpl.java From Camera2 with Apache License 2.0 | 6 votes |
@Override public String dumpDeviceSettings() { Parameters parameters = getParameters(); if (parameters != null) { String flattened = getParameters().flatten(); StringTokenizer tokenizer = new StringTokenizer(flattened, ";"); String dumpedSettings = new String(); while (tokenizer.hasMoreElements()) { dumpedSettings += tokenizer.nextToken() + '\n'; } return dumpedSettings; } else { return "[no parameters retrieved]"; } }
Example #22
Source File: CameraWrapper.java From VideoCamera with Apache License 2.0 | 6 votes |
@TargetApi(VERSION_CODES.HONEYCOMB) protected List<Size> getSupportedVideoSizes(int currentSdkInt) { Parameters params = mNativeCamera.getNativeCameraParameters(); List<Size> supportedVideoSizes; if (currentSdkInt < Build.VERSION_CODES.HONEYCOMB) { CLog.e(CLog.CAMERA, "Using supportedPreviewSizes iso supportedVideoSizes due to API restriction"); supportedVideoSizes = params.getSupportedPreviewSizes(); } else if (params.getSupportedVideoSizes() == null) { CLog.e(CLog.CAMERA, "Using supportedPreviewSizes because supportedVideoSizes is null"); supportedVideoSizes = params.getSupportedPreviewSizes(); } else { supportedVideoSizes = params.getSupportedVideoSizes(); } return supportedVideoSizes; }
Example #23
Source File: CameraPreview.java From Android-IP-Camera with MIT License | 6 votes |
public CameraPreview(Context context, Camera camera) { super(context); mCamera = camera; mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android versions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); Parameters params = mCamera.getParameters(); List<Size> sizes = params.getSupportedPreviewSizes(); for (Size s : sizes) { Log.i(TAG, "preview size = " + s.width + ", " + s.height); } params.setPreviewSize(640, 480); // set preview size. smaller is better mCamera.setParameters(params); mPreviewSize = mCamera.getParameters().getPreviewSize(); Log.i(TAG, "preview size = " + mPreviewSize.width + ", " + mPreviewSize.height); int format = mCamera.getParameters().getPreviewFormat(); mFrameLength = mPreviewSize.width * mPreviewSize.height * ImageFormat.getBitsPerPixel(format) / 8; }
Example #24
Source File: Utils.java From code-scanner with MIT License | 6 votes |
public static void setAutoFocusMode(@NonNull final Parameters parameters, final AutoFocusMode autoFocusMode) { final List<String> focusModes = parameters.getSupportedFocusModes(); if (focusModes == null || focusModes.isEmpty()) { return; } if (autoFocusMode == AutoFocusMode.CONTINUOUS) { if (Parameters.FOCUS_MODE_CONTINUOUS_PICTURE.equals(parameters.getFocusMode())) { return; } if (focusModes.contains(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) { parameters.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); return; } } if (Parameters.FOCUS_MODE_AUTO.equals(parameters.getFocusMode())) { return; } if (focusModes.contains(Parameters.FOCUS_MODE_AUTO)) { parameters.setFocusMode(Parameters.FOCUS_MODE_AUTO); } }
Example #25
Source File: CameraEngine.java From TikTok with Apache License 2.0 | 6 votes |
/** * ------------- 设置闪光灯模式 ------------------ * @param flashMode */ public static void setFlashMode(int flashMode){ try{ Camera.Parameters parameters = camera.getParameters(); if(flashMode == FLASH_MODE_OFF){ parameters.setFlashMode(Camera.Parameters.FLASH_MODE_OFF); }else if(flashMode == FLASH_MODE_ON){ parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH); }else{ parameters.setFlashMode(Camera.Parameters.FLASH_MODE_AUTO); } // CacheUtil.putInt(AppUtil.getApplicationContext(), FLASH_MODE, flashMode); camera.setParameters(parameters); }catch (Exception e){ e.printStackTrace(); } }
Example #26
Source File: CameraView.java From LLApp with Apache License 2.0 | 5 votes |
/** * 获取最大缩放级别,最大为40 * @return */ @Override public int getMaxZoom(){ if(mCamera==null) return -1; Parameters parameters=mCamera.getParameters(); if(!parameters.isZoomSupported()) return -1; return parameters.getMaxZoom()>40?40:parameters.getMaxZoom(); }
Example #27
Source File: CameraManager.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
public void closeLight() //关闭闪光灯 { if(camera!=null) { Parameters parameter=camera.getParameters(); parameter.setFlashMode(Parameters.FLASH_MODE_OFF); camera.setParameters(parameter); } }
Example #28
Source File: FaceScanner.java From Eye-blink-detector with MIT License | 5 votes |
/** * Check if the flash is on. * * @return state of the flash. */ public boolean isFlashOn() { if (!useCamera) { return false; } Camera.Parameters params = mCamera.getParameters(); return params.getFlashMode().equals(Parameters.FLASH_MODE_TORCH); }
Example #29
Source File: Camera1Handler.java From Augendiagnose with GNU General Public License v2.0 | 5 votes |
@Override public final void setFocusMode(@Nullable final FocusMode focusMode) { if (focusMode == null) { mCurrentFocusMode = null; return; } switch (focusMode) { case AUTO: mCurrentFocusMode = Parameters.FOCUS_MODE_AUTO; break; case MACRO: mCurrentFocusMode = Parameters.FOCUS_MODE_MACRO; break; case CONTINUOUS: mCurrentFocusMode = Parameters.FOCUS_MODE_CONTINUOUS_PICTURE; break; case FIXED: mCurrentFocusMode = Parameters.FOCUS_MODE_FIXED; break; default: mCurrentFocusMode = null; break; } updateFocus(); }
Example #30
Source File: CameraPreview.java From CuXtomCam with Apache License 2.0 | 5 votes |
/** * Possible Picture Orientation fix * * @param param * @param orientation */ public void onOrientationChanged(Parameters param, int orientation) { if (orientation == OrientationEventListener.ORIENTATION_UNKNOWN) return; CameraInfo info = new CameraInfo(); Camera.getCameraInfo(0, info); orientation = (orientation + 45) / 90 * 90; int rotation = 0; if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { rotation = (info.orientation - orientation + 360) % 360; } else { // back-facing camera rotation = (info.orientation + orientation) % 360; } param.setRotation(rotation); }