From 786ff4f4ca2374bdd9177f2e24b503d43e7a3b93 Mon Sep 17 00:00:00 2001 From: liyujie <2352380935@qq.com> Date: Thu, 28 Aug 2025 12:04:21 +0000 Subject: [PATCH] [4/4]解决USB摄像头打开相机预览界面绿屏 --- android/packages/apps/Camera2/src/com/android/camera/settings/ResolutionUtil.java | 14 +++++++++++++- 1 files changed, 13 insertions(+), 1 deletions(-) diff --git a/android/packages/apps/Camera2/src/com/android/camera/settings/ResolutionUtil.java b/android/packages/apps/Camera2/src/com/android/camera/settings/ResolutionUtil.java old mode 100755 new mode 100644 index 73586d0..d4182ba --- a/android/packages/apps/Camera2/src/com/android/camera/settings/ResolutionUtil.java +++ b/android/packages/apps/Camera2/src/com/android/camera/settings/ResolutionUtil.java @@ -359,6 +359,16 @@ return Math.abs(ar1.toDouble() - ar2.toDouble()) < ASPECT_RATIO_TOLERANCE; } + public static boolean is16BitAligned(Size size) { + int width = size.getWidth(); + int height = size.getHeight(); + if (((width & 15) == 0) && ((height & 15) == 0)) { + return true; + } else { + return false; + } + } + /** * Selects the maximal resolution for the given desired aspect ratio from all available * resolutions. If no resolution exists for the desired aspect ratio, return a resolution @@ -392,9 +402,11 @@ for (Size size : sizes) { Rational aspectRatio = getAspectRatio(size); // Skip if the aspect ratio is not desired. - if (!hasSameAspectRatio(aspectRatio, desiredAspectRatio)) { + if (!hasSameAspectRatio(aspectRatio, desiredAspectRatio) || + !is16BitAligned(size)) { continue; } + int pixelNum = size.getWidth() * size.getHeight(); if (pixelNum > maxPixelNumWithAspect) { maxPixelNumWithAspect = pixelNum; -- Gitblit v1.6.2