Java Code Examples for android.util.Size#getHeight()
The following examples show how to use
android.util.Size#getHeight() .
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: Camera2VideoFragment.java From android-Camera2Video with Apache License 2.0 | 6 votes |
/** * Given {@code choices} of {@code Size}s supported by a camera, chooses the smallest one whose * width and height are at least as large as the respective requested values, and whose aspect * ratio matches with the specified value. * * @param choices The list of sizes that the camera supports for the intended output class * @param width The minimum desired width * @param height The minimum desired height * @param aspectRatio The aspect ratio * @return The optimal {@code Size}, or an arbitrary one if none were big enough */ private static Size chooseOptimalSize(Size[] choices, int width, int height, Size aspectRatio) { // Collect the supported resolutions that are at least as big as the preview Surface List<Size> bigEnough = new ArrayList<>(); int w = aspectRatio.getWidth(); int h = aspectRatio.getHeight(); for (Size option : choices) { if (option.getHeight() == option.getWidth() * h / w && option.getWidth() >= width && option.getHeight() >= height) { bigEnough.add(option); } } // Pick the smallest of those, assuming we found any if (bigEnough.size() > 0) { return Collections.min(bigEnough, new CompareSizesByArea()); } else { Log.e(TAG, "Couldn't find any suitable preview size"); return choices[0]; } }
Example 2
Source File: PinnedStackController.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Returns the current bounds (or the default bounds if there are no current bounds) with the * specified aspect ratio. */ Rect transformBoundsToAspectRatio(Rect stackBounds, float aspectRatio, boolean useCurrentMinEdgeSize) { // Save the snap fraction, calculate the aspect ratio based on screen size final float snapFraction = mSnapAlgorithm.getSnapFraction(stackBounds, getMovementBounds(stackBounds)); final int minEdgeSize = useCurrentMinEdgeSize ? mCurrentMinSize : mDefaultMinSize; final Size size = mSnapAlgorithm.getSizeForAspectRatio(aspectRatio, minEdgeSize, mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight); final int left = (int) (stackBounds.centerX() - size.getWidth() / 2f); final int top = (int) (stackBounds.centerY() - size.getHeight() / 2f); stackBounds.set(left, top, left + size.getWidth(), top + size.getHeight()); mSnapAlgorithm.applySnapFraction(stackBounds, getMovementBounds(stackBounds), snapFraction); if (mIsMinimized) { applyMinimizedOffset(stackBounds, getMovementBounds(stackBounds)); } return stackBounds; }
Example 3
Source File: Camera2Utils.java From HelloCamera2 with MIT License | 6 votes |
/** * 从sizeArray中找到满足16:9比例,且不超过maxPicturePixels指定的像素数的最大Size. * 若找不到,则选择满足16:9比例的最大Size(像素数可能超过maxPicturePixels),若仍找不到,返回最大Size。 * * @param sizeArray StreamConfigurationMap.getOutputSizes(ImageFormat.JPEG)得到的sizeArray * @param maxPicturePixels 最大可接受的照片像素数 * @return 找到满足16:9比例,且不超过maxPicturePixels指定的像素数的最大Size */ public static Size findBestSize(Size[] sizeArray, long maxPicturePixels) { //满足16:9,但超过maxAcceptedPixels的过大Size List<Size> tooLargeSizes = new ArrayList<>(); List<Size> immutableSizeList = Arrays.asList(sizeArray); //Arrays.asList返回的List是不可变的,需重新包装为java.util.ArrayList. List<Size> sizeList = new ArrayList<>(immutableSizeList); //按面积由大到小排序 Collections.sort(sizeList, (lhs, rhs) -> -compare(lhs.getWidth() * lhs.getHeight(), rhs.getWidth() * rhs.getHeight())); for (Size size : sizeList) { //非16:9的尺寸无视 if (!isWide(size)) continue; boolean notTooLarge = ((long) size.getWidth()) * ((long) size.getHeight()) <= maxPicturePixels; if (!notTooLarge) { tooLargeSizes.add(size); continue; } return size; } if (tooLargeSizes.size() > 0) { return tooLargeSizes.get(0); } else { return sizeList.get(0); } }
Example 4
Source File: CameraConnectionFragment.java From android-hpe with MIT License | 6 votes |
/** * Given {@code choices} of {@code Size}s supported by a camera, chooses the smallest one whose * width and height are at least as large as the respective requested values, and whose aspect * ratio matches with the specified value. * * @param choices The list of sizes that the camera supports for the intended output class * @param width The minimum desired width * @param height The minimum desired height * @param aspectRatio The aspect ratio * @return The optimal {@code Size}, or an arbitrary one if none were big enough */ @SuppressLint("LongLogTag") @DebugLog private static Size chooseOptimalSize( final Size[] choices, final int width, final int height, final Size aspectRatio) { // Collect the supported resolutions that are at least as big as the preview Surface final List<Size> bigEnough = new ArrayList<Size>(); for (final Size option : choices) { if (option.getHeight() >= MINIMUM_PREVIEW_SIZE && option.getWidth() >= MINIMUM_PREVIEW_SIZE) { Log.i(TAG, "Adding size: " + option.getWidth() + "x" + option.getHeight()); bigEnough.add(option); } else { Log.i(TAG, "Not adding size: " + option.getWidth() + "x" + option.getHeight()); } } // Pick the smallest of those, assuming we found any if (bigEnough.size() > 0) { final Size chosenSize = Collections.min(bigEnough, new CompareSizesByArea()); Log.i(TAG, "Chosen size: " + chosenSize.getWidth() + "x" + chosenSize.getHeight()); return chosenSize; } else { Log.e(TAG, "Couldn't find any suitable preview size"); return choices[0]; } }
Example 5
Source File: CameraXVideoCaptureHelper.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
private void shrinkCaptureArea() { Size screenSize = getScreenSize(); Size videoRecordingSize = VideoUtil.getVideoRecordingSize(); float scale = getSurfaceScaleForRecording(); float targetWidthForAnimation = videoRecordingSize.getWidth() * scale; float scaleX = targetWidthForAnimation / screenSize.getWidth(); if (scaleX == 1f) { float targetHeightForAnimation = videoRecordingSize.getHeight() * scale; if (screenSize.getHeight() == targetHeightForAnimation) { return; } cameraMetricsAnimator = ValueAnimator.ofFloat(screenSize.getHeight(), targetHeightForAnimation); } else { if (screenSize.getWidth() == targetWidthForAnimation) { return; } cameraMetricsAnimator = ValueAnimator.ofFloat(screenSize.getWidth(), targetWidthForAnimation); } ViewGroup.LayoutParams params = camera.getLayoutParams(); cameraMetricsAnimator.setInterpolator(new LinearInterpolator()); cameraMetricsAnimator.setDuration(200); cameraMetricsAnimator.addUpdateListener(animation -> { if (scaleX == 1f) { params.height = Math.round((float) animation.getAnimatedValue()); } else { params.width = Math.round((float) animation.getAnimatedValue()); } camera.setLayoutParams(params); }); cameraMetricsAnimator.start(); }
Example 6
Source File: Camera2VideoFragment.java From android-Camera2Video with Apache License 2.0 | 5 votes |
/** * In this sample, we choose a video size with 3x4 aspect ratio. Also, we don't use sizes * larger than 1080p, since MediaRecorder cannot handle such a high-resolution video. * * @param choices The list of available sizes * @return The video size */ private static Size chooseVideoSize(Size[] choices) { for (Size size : choices) { if (size.getWidth() == size.getHeight() * 4 / 3 && size.getWidth() <= 1080) { return size; } } Log.e(TAG, "Couldn't find any suitable video size"); return choices[choices.length - 1]; }
Example 7
Source File: CameraConnectionFragment.java From dbclf with Apache License 2.0 | 5 votes |
/** * Given {@code choices} of {@code Size}s supported by a camera, chooses the smallest one whose * width and height are at least as large as the minimum of both, or an exact match if possible. * * @param choices The list of sizes that the camera supports for the intended output class * @param width The minimum desired width * @param height The minimum desired height * @return The optimal {@code Size}, or an arbitrary one if none were big enough */ protected static Size chooseOptimalSize(final Size[] choices, final int width, final int height) { final int minSize = Math.max(Math.min(width, height), MINIMUM_PREVIEW_SIZE); final Size desiredSize = new Size(width, height); // Collect the supported resolutions that are at least as big as the preview Surface boolean exactSizeFound = false; final List<Size> bigEnough = new ArrayList<Size>(); for (final Size option : choices) { if (option.equals(desiredSize)) { // Set the size but don't return yet so that remaining sizes will still be logged. exactSizeFound = true; } if (option.getHeight() >= minSize && option.getWidth() >= minSize) { bigEnough.add(option); } } if (exactSizeFound) { return desiredSize; } // Pick the smallest of those, assuming we found any if (bigEnough.size() > 0) { final Size chosenSize = Collections.min(bigEnough, new CompareSizesByArea()); return chosenSize; } else { return choices[0]; } }
Example 8
Source File: Camera2BasicFragment.java From Android-Camera2-Front-with-Face-Detection with Apache License 2.0 | 5 votes |
/** * Given {@code choices} of {@code Size}s supported by a camera, choose the smallest one that * is at least as large as the respective texture view size, and that is at most as large as the * respective max size, and whose aspect ratio matches with the specified value. If such size * doesn't exist, choose the largest one that is at most as large as the respective max size, * and whose aspect ratio matches with the specified value. * * @param choices The list of sizes that the camera supports for the intended output * class * @param textureViewWidth The width of the texture view relative to sensor coordinate * @param textureViewHeight The height of the texture view relative to sensor coordinate * @param maxWidth The maximum width that can be chosen * @param maxHeight The maximum height that can be chosen * @param aspectRatio The aspect ratio * @return The optimal {@code Size}, or an arbitrary one if none were big enough */ private static Size chooseOptimalSize(Size[] choices, int textureViewWidth, int textureViewHeight, int maxWidth, int maxHeight, Size aspectRatio) { // Collect the supported resolutions that are at least as big as the preview Surface List<Size> bigEnough = new ArrayList<>(); // Collect the supported resolutions that are smaller than the preview Surface List<Size> notBigEnough = new ArrayList<>(); int w = aspectRatio.getWidth(); int h = aspectRatio.getHeight(); for (Size option : choices) { if (option.getWidth() <= maxWidth && option.getHeight() <= maxHeight && option.getHeight() == option.getWidth() * h / w) { if (option.getWidth() >= textureViewWidth && option.getHeight() >= textureViewHeight) { bigEnough.add(option); } else { notBigEnough.add(option); } } } // Pick the smallest of those big enough. If there is no one big enough, pick the // largest of those not big enough. if (bigEnough.size() > 0) { return Collections.min(bigEnough, new CompareSizesByArea()); } else if (notBigEnough.size() > 0) { return Collections.max(notBigEnough, new CompareSizesByArea()); } else { Log.e(TAG, "Couldn't find any suitable preview size"); return choices[0]; } }
Example 9
Source File: Camera2FilterActivity.java From EZFilter with MIT License | 5 votes |
private Size chooseOptimalSize(Size[] choices, int textureViewWidth, int textureViewHeight, int maxWidth, int maxHeight, Size aspectRatio) { // Collect the supported resolutions that are at least as big as the preview Surface List<Size> bigEnough = new ArrayList<>(); // Collect the supported resolutions that are smaller than the preview Surface List<Size> notBigEnough = new ArrayList<>(); int w = aspectRatio.getWidth(); int h = aspectRatio.getHeight(); for (Size option : choices) { if (option.getWidth() <= maxWidth && option.getHeight() <= maxHeight && option.getHeight() == option.getWidth() * h / w) { if (option.getWidth() >= textureViewWidth && option.getHeight() >= textureViewHeight) { bigEnough.add(option); } else { notBigEnough.add(option); } } } // Pick the smallest of those big enough. If there is no one big enough, pick the // largest of those not big enough. if (bigEnough.size() > 0) { return Collections.min(bigEnough, new CompareSizesByArea()); } else if (notBigEnough.size() > 0) { return Collections.max(notBigEnough, new CompareSizesByArea()); } else { return choices[0]; } }
Example 10
Source File: CameraConnectionFragment.java From next18-ai-in-motion with Apache License 2.0 | 5 votes |
/** * Given {@code choices} of {@code Size}s supported by a camera, chooses the smallest one whose * width and height are at least as large as the minimum of both, or an exact match if possible. * * @param choices The list of sizes that the camera supports for the intended output class * @param width The minimum desired width * @param height The minimum desired height * @return The optimal {@code Size}, or an arbitrary one if none were big enough */ protected static Size chooseOptimalSize(final Size[] choices, final int width, final int height) { final int minSize = Math.max(Math.min(width, height), MINIMUM_PREVIEW_SIZE); final Size desiredSize = new Size(width, height); // Collect the supported resolutions that are at least as big as the preview Surface boolean exactSizeFound = false; final List<Size> bigEnough = new ArrayList<Size>(); final List<Size> tooSmall = new ArrayList<Size>(); for (final Size option : choices) { if (option.equals(desiredSize)) { // Set the size but don't return yet so that remaining sizes will still be logged. exactSizeFound = true; } if (option.getHeight() >= minSize && option.getWidth() >= minSize) { bigEnough.add(option); } else { tooSmall.add(option); } } if (exactSizeFound) { return desiredSize; } // Pick the smallest of those, assuming we found any if (bigEnough.size() > 0) { final Size chosenSize = Collections.min(bigEnough, new CompareSizesByArea()); return chosenSize; } else { return choices[0]; } }
Example 11
Source File: Camera2VideoFragment.java From patrol-android with GNU General Public License v3.0 | 5 votes |
/** * In this sample, we choose a video size with 3x4 aspect ratio. Also, we don't use sizes * larger than 1080p, since MediaRecorder cannot handle such a high-resolution video. * * @param choices The list of available sizes * @return The video size */ private static Size chooseVideoSize(Size[] choices) { for (Size size : choices) { if (size.getWidth() == size.getHeight() * 4 / 3 && size.getWidth() <= 1080) { return size; } } Log.e(TAG, "Couldn't find any suitable video size"); return choices[choices.length - 1]; }
Example 12
Source File: CameraUtils.java From android-openGL-canvas with Apache License 2.0 | 5 votes |
/** * Given {@code choices} of {@code Size}s supported by a camera, choose the smallest one that * is at least as large as the respective texture view size, and that is at most as large as the * respective max size, and whose aspect ratio matches with the specified value. If such size * doesn't exist, choose the largest one that is at most as large as the respective max size, * and whose aspect ratio matches with the specified value. * * @param choices The list of sizes that the camera supports for the intended output * class * @param textureViewWidth The width of the texture view relative to sensor coordinate * @param textureViewHeight The height of the texture view relative to sensor coordinate * @param maxWidth The maximum width that can be chosen * @param maxHeight The maximum height that can be chosen * @param aspectRatio The aspect ratio * @return The optimal {@code Size}, or an arbitrary one if none were big enough */ @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public static Size chooseOptimalSize(Size[] choices, int textureViewWidth, int textureViewHeight, int maxWidth, int maxHeight, Size aspectRatio) { // Collect the supported resolutions that are at least as big as the preview Surface List<Size> bigEnough = new ArrayList<>(); // Collect the supported resolutions that are smaller than the preview Surface List<Size> notBigEnough = new ArrayList<>(); int w = aspectRatio.getWidth(); int h = aspectRatio.getHeight(); for (Size option : choices) { if (option.getWidth() <= maxWidth && option.getHeight() <= maxHeight && option.getHeight() == option.getWidth() * h / w) { if (option.getWidth() >= textureViewWidth && option.getHeight() >= textureViewHeight) { bigEnough.add(option); } else { notBigEnough.add(option); } } } // Pick the smallest of those big enough. If there is no one big enough, pick the // largest of those not big enough. if (bigEnough.size() > 0) { return Collections.min(bigEnough, new CompareSizesByArea()); } else if (notBigEnough.size() > 0) { return Collections.max(notBigEnough, new CompareSizesByArea()); } else { Log.e(TAG, "Couldn't find any suitable preview size"); return choices[0]; } }
Example 13
Source File: Camera2Wrapper.java From DeviceConnect-Android with MIT License | 5 votes |
/** * カメラの撮影サイズを設定します. * * @param pictureSize カメラの撮影サイズ */ public void setPictureSize(final Size pictureSize) { List<Size> sizes = getSupportedPictureSizes(); for (Size size : sizes) { if (size.getWidth() == pictureSize.getWidth() && size.getHeight() == pictureSize.getHeight()) { mPictureSize = pictureSize; return; } } throw new RuntimeException("Not found a match size."); }
Example 14
Source File: CameraConnectionFragment.java From fritz-examples with MIT License | 4 votes |
/** * Given {@code choices} of {@code Size}s supported by a camera, chooses the smallest one whose * width and height are at least as large as the minimum of both, or an exact match if possible. * * @param choices The list of sizes that the camera supports for the intended output class * @param width The minimum desired width * @param height The minimum desired height * @return The optimal {@code Size}, or an arbitrary one if none were big enough */ protected static Size chooseOptimalSize(final Size[] choices, final int width, final int height) { final int minSize = Math.max(Math.min(width, height), MINIMUM_PREVIEW_SIZE); final Size desiredSize = new Size(width, height); // Collect the supported resolutions that are at least as big as the preview Surface boolean exactSizeFound = false; final List<Size> bigEnough = new ArrayList<Size>(); final List<Size> tooSmall = new ArrayList<Size>(); for (final Size option : choices) { if (option.equals(desiredSize)) { // Set the size but don't return yet so that remaining sizes will still be logged. exactSizeFound = true; } if (option.getHeight() >= minSize && option.getWidth() >= minSize) { bigEnough.add(option); } else { tooSmall.add(option); } } Log.d(TAG, "Desired size: " + desiredSize + ", min size: " + minSize + "x" + minSize); Log.d(TAG, "Valid preview sizes: [" + TextUtils.join(", ", bigEnough) + "]"); Log.d(TAG, "Rejected preview sizes: [" + TextUtils.join(", ", tooSmall) + "]"); if (exactSizeFound) { Log.d(TAG, "Exact size match found."); return desiredSize; } // Pick the smallest of those, assuming we found any if (bigEnough.size() > 0) { final Size chosenSize = Collections.min(bigEnough, new CompareSizesByArea()); Log.d(TAG, "Chosen size: " + chosenSize.getWidth() + "x" + chosenSize.getHeight()); return chosenSize; } else { Log.e(TAG, "Couldn't find any suitable preview size"); return choices[0]; } }
Example 15
Source File: SettingsPreferenceActivity.java From DeviceConnect-Android with MIT License | 4 votes |
private String getPreviewSizeSettingValue(final Size previewSize) { return previewSize.getWidth() + " x " + previewSize.getHeight(); }
Example 16
Source File: HostMediaRecorder.java From DeviceConnect-Android with MIT License | 4 votes |
public PictureSize(final Size size) { this(size.getWidth(), size.getHeight()); }
Example 17
Source File: ClassifierActivity.java From tensorflow-classifier-android with Apache License 2.0 | 4 votes |
@Override public void onPreviewSizeChosen(final Size size, final int rotation) { final float textSizePx = TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, TEXT_SIZE_DIP, getResources().getDisplayMetrics()); borderedText = new BorderedText(textSizePx); borderedText.setTypeface(Typeface.MONOSPACE); classifier = TensorFlowImageClassifier.create( getAssets(), MODEL_FILE, LABEL_FILE, INPUT_SIZE, IMAGE_MEAN, IMAGE_STD, INPUT_NAME, OUTPUT_NAME); previewWidth = size.getWidth(); previewHeight = size.getHeight(); final Display display = getWindowManager().getDefaultDisplay(); final int screenOrientation = display.getRotation(); LOGGER.i("Sensor orientation: %d, Screen orientation: %d", rotation, screenOrientation); sensorOrientation = rotation + screenOrientation; LOGGER.i("Initializing at size %dx%d", previewWidth, previewHeight); rgbFrameBitmap = Bitmap.createBitmap(previewWidth, previewHeight, Config.ARGB_8888); croppedBitmap = Bitmap.createBitmap(INPUT_SIZE, INPUT_SIZE, Config.ARGB_8888); frameToCropTransform = ImageUtils.getTransformationMatrix( previewWidth, previewHeight, INPUT_SIZE, INPUT_SIZE, sensorOrientation, MAINTAIN_ASPECT); cropToFrameTransform = new Matrix(); frameToCropTransform.invert(cropToFrameTransform); addCallback( new DrawCallback() { @Override public void drawCallback(final Canvas canvas) { renderDebug(canvas); } }); }
Example 18
Source File: CameraConnectionFragment.java From fritz-examples with MIT License | 4 votes |
/** * Given {@code choices} of {@code Size}s supported by a camera, chooses the smallest one whose * width and height are at least as large as the minimum of both, or an exact match if possible. * * @param choices The list of sizes that the camera supports for the intended output class * @param width The minimum desired width * @param height The minimum desired height * @return The optimal {@code Size}, or an arbitrary one if none were big enough */ protected static Size chooseOptimalSize(final Size[] choices, final int width, final int height) { final int minSize = Math.max(Math.min(width, height), MINIMUM_PREVIEW_SIZE); final Size desiredSize = new Size(width, height); // Collect the supported resolutions that are at least as big as the preview Surface boolean exactSizeFound = false; final List<Size> bigEnough = new ArrayList<Size>(); final List<Size> tooSmall = new ArrayList<Size>(); for (final Size option : choices) { if (option.equals(desiredSize)) { // Set the size but don't return yet so that remaining sizes will still be logged. exactSizeFound = true; } if (option.getHeight() >= minSize && option.getWidth() >= minSize) { bigEnough.add(option); } else { tooSmall.add(option); } } Log.d(TAG, "Desired size: " + desiredSize + ", min size: " + minSize + "x" + minSize); Log.d(TAG, "Valid preview sizes: [" + TextUtils.join(", ", bigEnough) + "]"); Log.d(TAG, "Rejected preview sizes: [" + TextUtils.join(", ", tooSmall) + "]"); if (exactSizeFound) { Log.d(TAG, "Exact size match found."); return desiredSize; } // Pick the smallest of those, assuming we found any if (bigEnough.size() > 0) { final Size chosenSize = Collections.min(bigEnough, new CompareSizesByArea()); Log.d(TAG, "Chosen size: " + chosenSize.getWidth() + "x" + chosenSize.getHeight()); return chosenSize; } else { Log.e(TAG, "Couldn't find any suitable preview size"); return choices[0]; } }
Example 19
Source File: CameraConnectionFragment.java From tensorflow-classifier-android with Apache License 2.0 | 4 votes |
/** * Given {@code choices} of {@code Size}s supported by a camera, chooses the smallest one whose * width and height are at least as large as the minimum of both, or an exact match if possible. * * @param choices The list of sizes that the camera supports for the intended output class * @param width The minimum desired width * @param height The minimum desired height * @return The optimal {@code Size}, or an arbitrary one if none were big enough */ protected static Size chooseOptimalSize(final Size[] choices, final int width, final int height) { final int minSize = Math.max(Math.min(width, height), MINIMUM_PREVIEW_SIZE); final Size desiredSize = new Size(width, height); // Collect the supported resolutions that are at least as big as the preview Surface boolean exactSizeFound = false; final List<Size> bigEnough = new ArrayList<Size>(); final List<Size> tooSmall = new ArrayList<Size>(); for (final Size option : choices) { if (option.equals(desiredSize)) { // Set the size but don't return yet so that remaining sizes will still be logged. exactSizeFound = true; } if (option.getHeight() >= minSize && option.getWidth() >= minSize) { bigEnough.add(option); } else { tooSmall.add(option); } } LOGGER.i("Desired size: " + desiredSize + ", min size: " + minSize + "x" + minSize); LOGGER.i("Valid preview sizes: [" + TextUtils.join(", ", bigEnough) + "]"); LOGGER.i("Rejected preview sizes: [" + TextUtils.join(", ", tooSmall) + "]"); if (exactSizeFound) { LOGGER.i("Exact size match found."); return desiredSize; } // Pick the smallest of those, assuming we found any if (bigEnough.size() > 0) { final Size chosenSize = Collections.min(bigEnough, new CompareSizesByArea()); LOGGER.i("Chosen size: " + chosenSize.getWidth() + "x" + chosenSize.getHeight()); return chosenSize; } else { LOGGER.e("Couldn't find any suitable preview size"); return choices[0]; } }
Example 20
Source File: Camera2RawFragment.java From android-Camera2Raw with Apache License 2.0 | 2 votes |
/** * Return true if the two given {@link Size}s have the same aspect ratio. * * @param a first {@link Size} to compare. * @param b second {@link Size} to compare. * @return true if the sizes have the same aspect ratio, otherwise false. */ private static boolean checkAspectsEqual(Size a, Size b) { double aAspect = a.getWidth() / (double) a.getHeight(); double bAspect = b.getWidth() / (double) b.getHeight(); return Math.abs(aAspect - bAspect) <= ASPECT_RATIO_TOLERANCE; }