Java Code Examples for android.hardware.Camera.Parameters#setFocusMode()
The following examples show how to use
android.hardware.Camera.Parameters#setFocusMode() .
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 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 2
Source File: Utils.java From code-scanner with MIT License | 6 votes |
public static void disableAutoFocus(@NonNull final Parameters parameters) { final List<String> focusModes = parameters.getSupportedFocusModes(); if (focusModes == null || focusModes.isEmpty()) { return; } final String focusMode = parameters.getFocusMode(); if (focusModes.contains(Parameters.FOCUS_MODE_FIXED)) { if (Parameters.FOCUS_MODE_FIXED.equals(focusMode)) { return; } else { parameters.setFocusMode(Parameters.FOCUS_MODE_FIXED); return; } } if (focusModes.contains(Parameters.FOCUS_MODE_AUTO)) { if (!Parameters.FOCUS_MODE_AUTO.equals(focusMode)) { parameters.setFocusMode(Parameters.FOCUS_MODE_AUTO); } } }
Example 3
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 4
Source File: CameraView.java From Zom-Android-XMPP with GNU General Public License v3.0 | 6 votes |
private void startPreview(SurfaceHolder holder) { try { Parameters params = camera.getParameters(); if (params.getSupportedFocusModes().contains( Camera.Parameters.FOCUS_MODE_AUTO)) { params.setFocusMode(Camera.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 5
Source File: CameraView.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
@TargetApi(14) private void onCameraReady(final @NonNull Camera camera) { final Parameters parameters = camera.getParameters(); if (VERSION.SDK_INT >= 14) { parameters.setRecordingHint(true); final List<String> focusModes = parameters.getSupportedFocusModes(); if (focusModes.contains(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) { parameters.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); } else if (focusModes.contains(Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) { parameters.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_VIDEO); } } displayOrientation = CameraUtils.getCameraDisplayOrientation(getActivity(), getCameraInfo()); camera.setDisplayOrientation(displayOrientation); camera.setParameters(parameters); enqueueTask(new PostInitializationTask<Void>() { @Override protected Void onRunBackground() { try { camera.setPreviewDisplay(surface.getHolder()); startPreview(parameters); } catch (Exception e) { Log.w(TAG, "couldn't set preview display", e); } return null; } }); }
Example 6
Source File: Camera1Controller.java From pixelvisualcorecamera with Apache License 2.0 | 5 votes |
/** * Configures camera parameters common to all configurations. * Must be called before preview started. */ public void setDefaultParameters(int displayRotation) { Log.i(TAG, "setDefaultParameters"); assertState(STATE_ACQUIRED, "Default parameters may only be set before a preview is started"); CameraInfo info = new CameraInfo(); Camera.getCameraInfo(cameraId, info); boolean lensFacingFront = (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT); int previewOrientationDegrees = Orientation.getPreviewOrientation(lensFacingFront, displayRotation, info.orientation); camera.setDisplayOrientation(previewOrientationDegrees); Parameters params = camera.getParameters(); // We happen to know the preview sizes available for Pixel 2. params.setPreviewSize(Utils.MAX_PREVIEW_WIDTH, Utils.MAX_PREVIEW_HEIGHT); params.setRotation( Orientation.getOutputOrientation(lensFacingFront, displayRotation, info.orientation)); // Continuous picture is not supported Pixel 2's front camera. List<String> supportFocusModes = params.getSupportedFocusModes(); if (supportFocusModes.contains(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) { Log.i(TAG, "setting continuous picture focus mode"); params.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); } // HDR+: Flash mode must be off. params.setFlashMode(Parameters.FLASH_MODE_OFF); // HDR+: Color effect must be none. params.setColorEffect(Parameters.EFFECT_NONE); // HDR+: White balance must be auto. params.setWhiteBalance(Parameters.WHITE_BALANCE_AUTO); camera.setParameters(params); }
Example 7
Source File: Utils.java From code-scanner with MIT License | 5 votes |
public static void configureFocusModeForTouch(@NonNull final Parameters parameters) { if (Parameters.FOCUS_MODE_AUTO.equals(parameters.getFocusMode())) { return; } final List<String> focusModes = parameters.getSupportedFocusModes(); if (focusModes != null && focusModes.contains(Parameters.FOCUS_MODE_AUTO)) { parameters.setFocusMode(Parameters.FOCUS_MODE_AUTO); } }
Example 8
Source File: OpenglActivity.java From MegviiFacepp-Android-SDK with Apache License 2.0 | 5 votes |
private void autoFocus() { if (mCamera != null && isBackCamera) { mCamera.cancelAutoFocus(); Parameters parameters = mCamera.getParameters(); parameters.setFocusMode(Parameters.FOCUS_MODE_AUTO); mCamera.setParameters(parameters); mCamera.autoFocus(null); } }
Example 9
Source File: CameraView.java From deltachat-android with GNU General Public License v3.0 | 5 votes |
@TargetApi(14) private void onCameraReady(final @NonNull Camera camera) { final Parameters parameters = camera.getParameters(); if (VERSION.SDK_INT >= 14) { parameters.setRecordingHint(true); final List<String> focusModes = parameters.getSupportedFocusModes(); if (focusModes.contains(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) { parameters.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); } else if (focusModes.contains(Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) { parameters.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_VIDEO); } } displayOrientation = CameraUtils.getCameraDisplayOrientation(getActivity(), getCameraInfo()); camera.setDisplayOrientation(displayOrientation); camera.setParameters(parameters); enqueueTask(new PostInitializationTask<Void>() { @Override protected Void onRunBackground() { try { camera.setPreviewDisplay(surface.getHolder()); startPreview(parameters); } catch (Exception e) { Log.w(TAG, "couldn't set preview display", e); } return null; } }); }
Example 10
Source File: Camera1Handler.java From Augendiagnose with GNU General Public License v2.0 | 5 votes |
/** * Update the focus. */ private void updateFocus() { if (mCamera != null) { Parameters parameters = mCamera.getParameters(); parameters.setFocusMode(mCurrentFocusMode); mCamera.setParameters(parameters); } }
Example 11
Source File: CameraEngine.java From TikTok with Apache License 2.0 | 4 votes |
public static void setDefaultParameters(){ if(camera == null){ return ; } Parameters parameters = camera.getParameters(); if (parameters.getSupportedFocusModes().contains( Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) { parameters.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); } Size previewSize = CameraUtils.getLargePreviewSize(camera); parameters.setPreviewSize(PREVIEW_WIDTH, PREVIEW_HEIGHT); if(!isFrameRateSure && mRealFrameRate == CAMERA_FRAME_RATE){ List<int[]> fpsList = parameters.getSupportedPreviewFpsRange(); int tempFps = 30001; for(int i=0;i<fpsList.size();i++){ int[] fps = fpsList.get(i); if(fps[0] == fps[1]){ if(fps[0] >= (CAMERA_FRAME_RATE * 1000) && fps[0]<= tempFps){ tempFps = fps[0]; } } } if(tempFps == 30001){ mRealFrameRate = CAMERA_FRAME_RATE; }else{ mRealFrameRate = tempFps/1000; } } parameters.setPreviewFpsRange(mRealFrameRate * 1000,mRealFrameRate * 1000); parameters.setPreviewFrameRate(mRealFrameRate); Size pictureSize = CameraUtils.getLargePictureSize(camera); parameters.setPictureSize(pictureSize.width, pictureSize.height); parameters.setRotation(getRightCameraOrientation(CameraEngine.cameraID)); // parameters.setExposureCompensation(-1); camera.setParameters(parameters); // DebugTool.warn("CameraEngineExposureCompensation:" + parameters.getMinExposureCompensation() + "," + parameters.getMaxExposureCompensation()); // camera.setDisplayOrientation(getRightCameraOrientation(CameraEngine.cameraID)); // new Handler().postDelayed(new Runnable() { // @Override // public void run() { // int[] fpsa = new int[2]; // camera.getParameters().getPreviewFpsRange(fpsa); // DebugTool.warn("CameraEnginePreviewFpsAA:" + fpsa[0] + "," + fpsa[1] + "," + camera.getParameters().getPreviewFrameRate()); // } // },2000); // if(!isFrameReal && CacheUtil.getInt(AppUtil.getApplicationContext(),FRAME_RATE_KEY,0) == 0){ // byte[] data = new byte[PREVIEW_WIDTH*PREVIEW_HEIGHT*3/2]; // camera.addCallbackBuffer(data); // camera.setPreviewCallbackWithBuffer(new Camera.PreviewCallback() { // @Override // public void onPreviewFrame(byte[] data, Camera camera) { // mFrameCount++; // DebugTool.warn("CameraPreviewCallback:" + mFrameCount); // CameraEngine.camera.addCallbackBuffer(data); // if(mFrameStartTime > 0 && System.currentTimeMillis()-mFrameStartTime >= 2000){//开始确定帧率 // camera.setPreviewCallbackWithBuffer(null); // isFrameStart = false; // isFrameReal = true; // // if(mFrameCount>=mRealFrameRate){ // if(mFrameCount/2-mRealFrameRate<4){ // return ; // }else{ // mRealFrameRate = mFrameCount/2 + (5-mFrameCount%5); // } // } // DebugTool.warn("CameraPreviewCallback:mRealFrameRate:" + mRealFrameRate); // return ; // } // if(!isFrameStart){ // isFrameStart = true; // mFrameStartTime = System.currentTimeMillis(); // } // } // }); // } }
Example 12
Source File: AndroidCameraAgentImpl.java From Camera2 with Apache License 2.0 | 4 votes |
private void applySettingsToParameters(final CameraSettings settings, final Parameters parameters) { final CameraCapabilities.Stringifier stringifier = mCapabilities.getStringifier(); Size photoSize = settings.getCurrentPhotoSize(); parameters.setPictureSize(photoSize.width(), photoSize.height()); Size previewSize = settings.getCurrentPreviewSize(); parameters.setPreviewSize(previewSize.width(), previewSize.height()); if (settings.getPreviewFrameRate() == -1) { parameters.setPreviewFpsRange(settings.getPreviewFpsRangeMin(), settings.getPreviewFpsRangeMax()); } else { parameters.setPreviewFrameRate(settings.getPreviewFrameRate()); } parameters.setPreviewFormat(settings.getCurrentPreviewFormat()); parameters.setJpegQuality(settings.getPhotoJpegCompressionQuality()); if (mCapabilities.supports(CameraCapabilities.Feature.ZOOM)) { parameters.setZoom(zoomRatioToIndex(settings.getCurrentZoomRatio(), parameters.getZoomRatios())); } parameters.setExposureCompensation(settings.getExposureCompensationIndex()); if (mCapabilities.supports(CameraCapabilities.Feature.AUTO_EXPOSURE_LOCK)) { parameters.setAutoExposureLock(settings.isAutoExposureLocked()); } parameters.setFocusMode(stringifier.stringify(settings.getCurrentFocusMode())); if (mCapabilities.supports(CameraCapabilities.Feature.AUTO_WHITE_BALANCE_LOCK)) { parameters.setAutoWhiteBalanceLock(settings.isAutoWhiteBalanceLocked()); } if (settings.getWhiteBalance() != null) { parameters.setWhiteBalance(stringifier.stringify(settings.getWhiteBalance())); } if (mCapabilities.supports(CameraCapabilities.Feature.FOCUS_AREA)) { if (settings.getFocusAreas().size() != 0) { parameters.setFocusAreas(settings.getFocusAreas()); } else { parameters.setFocusAreas(null); } } if (mCapabilities.supports(CameraCapabilities.Feature.METERING_AREA)) { if (settings.getMeteringAreas().size() != 0) { parameters.setMeteringAreas(settings.getMeteringAreas()); } else { parameters.setMeteringAreas(null); } } if (settings.getCurrentFlashMode() != CameraCapabilities.FlashMode.NO_FLASH) { parameters.setFlashMode(stringifier.stringify(settings.getCurrentFlashMode())); } if (settings.getCurrentSceneMode() != CameraCapabilities.SceneMode.NO_SCENE_MODE) { if (settings.getCurrentSceneMode() != null) { parameters .setSceneMode(stringifier.stringify(settings.getCurrentSceneMode())); } } parameters.setRecordingHint(settings.isRecordingHintEnabled()); Size jpegThumbSize = settings.getExifThumbnailSize(); if (jpegThumbSize != null) { parameters.setJpegThumbnailSize(jpegThumbSize.width(), jpegThumbSize.height()); } parameters.setPictureFormat(settings.getCurrentPhotoFormat()); CameraSettings.GpsData gpsData = settings.getGpsData(); if (gpsData == null) { parameters.removeGpsData(); } else { parameters.setGpsTimestamp(gpsData.timeStamp); if (gpsData.processingMethod != null) { // It's a hack since we always use GPS time stamp but does // not use other fields sometimes. Setting processing // method to null means the other fields should not be used. parameters.setGpsAltitude(gpsData.altitude); parameters.setGpsLatitude(gpsData.latitude); parameters.setGpsLongitude(gpsData.longitude); parameters.setGpsProcessingMethod(gpsData.processingMethod); } } }
Example 13
Source File: CameraWrapper.java From VideoCamera with Apache License 2.0 | 4 votes |
public void enableAutoFocus() { final Parameters params = mNativeCamera.getNativeCameraParameters(); params.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_VIDEO); mNativeCamera.updateNativeCameraParameters(params); }
Example 14
Source File: CameraWrapper.java From LandscapeVideoCamera with Apache License 2.0 | 4 votes |
public void enableAutoFocus() { final Parameters params = mNativeCamera.getNativeCameraParameters(); params.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_VIDEO); mNativeCamera.updateNativeCameraParameters(params); }
Example 15
Source File: CameraWizard.java From OnionCamera with MIT License | 4 votes |
public void setAutofocus() { Parameters parameters = camera.getParameters(); parameters.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_VIDEO); camera.setParameters(parameters); }