Java Code Examples for android.hardware.Camera.Parameters#setFocusAreas()
The following examples show how to use
android.hardware.Camera.Parameters#setFocusAreas() .
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: Utils.java From code-scanner with MIT License | 6 votes |
public static void configureFocusArea(@NonNull final Parameters parameters, @NonNull final Rect area, final int width, final int height, final int orientation) { final List<Area> areas = new ArrayList<>(1); final Rect rotatedArea = area.rotate(-orientation, width / 2f, height / 2f).bound(0, 0, width, height); areas.add(new Area(new android.graphics.Rect(mapCoordinate(rotatedArea.getLeft(), width), mapCoordinate(rotatedArea.getTop(), height), mapCoordinate(rotatedArea.getRight(), width), mapCoordinate(rotatedArea.getBottom(), height)), 1000)); if (parameters.getMaxNumFocusAreas() > 0) { parameters.setFocusAreas(areas); } if (parameters.getMaxNumMeteringAreas() > 0) { parameters.setMeteringAreas(areas); } }
Example 2
Source File: CameraProxy.java From CameraDemo with Apache License 2.0 | 5 votes |
public void focusOnPoint(int x, int y, int width, int height) { Log.v(TAG, "touch point (" + x + ", " + y + ")"); if (mCamera == null) { return; } Parameters parameters = mCamera.getParameters(); // 1.先要判断是否支持设置聚焦区域 if (parameters.getMaxNumFocusAreas() > 0) { // 2.以触摸点为中心点,view窄边的1/4为聚焦区域的默认边长 int length = Math.min(width, height) >> 3; // 1/8的长度 int left = x - length; int top = y - length; int right = x + length; int bottom = y + length; // 3.映射,因为相机聚焦的区域是一个(-1000,-1000)到(1000,1000)的坐标区域 left = left * 2000 / width - 1000; top = top * 2000 / height - 1000; right = right * 2000 / width - 1000; bottom = bottom * 2000 / height - 1000; // 4.判断上述矩形区域是否超过边界,若超过则设置为临界值 left = left < -1000 ? -1000 : left; top = top < -1000 ? -1000 : top; right = right > 1000 ? 1000 : right; bottom = bottom > 1000 ? 1000 : bottom; Log.d(TAG, "focus area (" + left + ", " + top + ", " + right + ", " + bottom + ")"); ArrayList<Camera.Area> areas = new ArrayList<>(); areas.add(new Camera.Area(new Rect(left, top, right, bottom), 600)); parameters.setFocusAreas(areas); } try { mCamera.cancelAutoFocus(); // 先要取消掉进程中所有的聚焦功能 mCamera.setParameters(parameters); mCamera.autoFocus(this); // 调用聚焦 } catch (Exception e) { e.printStackTrace(); } }
Example 3
Source File: CameraView.java From LLApp with Apache License 2.0 | 5 votes |
/** * 手动聚焦 * @param point 触屏坐标 */ protected void onFocus(Point point,AutoFocusCallback callback){ Parameters parameters=mCamera.getParameters(); //不支持设置自定义聚焦,则使用自动聚焦,返回 if (parameters.getMaxNumFocusAreas()<=0) { mCamera.autoFocus(callback); return; } List<Area> areas=new ArrayList<Area>(); int left=point.x-300; int top=point.y-300; int right=point.x+300; int bottom=point.y+300; left=left<-1000?-1000:left; top=top<-1000?-1000:top; right=right>1000?1000:right; bottom=bottom>1000?1000:bottom; areas.add(new Area(new Rect(left,top,right,bottom), 100)); parameters.setFocusAreas(areas); try { //本人使用的小米手机在设置聚焦区域的时候经常会出异常,看日志发现是框架层的字符串转int的时候出错了, //目测是小米修改了框架层代码导致,在此try掉,对实际聚焦效果没影响 mCamera.setParameters(parameters); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } mCamera.autoFocus(callback); }
Example 4
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); } } }