|
39 | 39 | import java.util.Arrays; |
40 | 40 | import java.util.Set; |
41 | 41 | import java.util.SortedSet; |
42 | | -import java.util.TreeSet; |
43 | 42 |
|
| 43 | +@SuppressWarnings("MissingPermission") |
44 | 44 | @TargetApi(21) |
45 | 45 | class Camera2 extends CameraViewImpl { |
46 | 46 |
|
@@ -417,10 +417,19 @@ private void collectCameraInfo() { |
417 | 417 | } |
418 | 418 | mPreviewSizes.clear(); |
419 | 419 | for (android.util.Size size : map.getOutputSizes(mPreview.getOutputClass())) { |
420 | | - mPreviewSizes.add(new Size(size.getWidth(), size.getHeight())); |
| 420 | + int width = size.getWidth(); |
| 421 | + int height = size.getHeight(); |
| 422 | + if (width <= MAX_PREVIEW_WIDTH && height <= MAX_PREVIEW_HEIGHT) { |
| 423 | + mPreviewSizes.add(new Size(width, height)); |
| 424 | + } |
421 | 425 | } |
422 | 426 | mPictureSizes.clear(); |
423 | 427 | collectPictureSizes(mPictureSizes, map); |
| 428 | + for (AspectRatio ratio : mPreviewSizes.ratios()) { |
| 429 | + if (!mPictureSizes.ratios().contains(ratio)) { |
| 430 | + mPreviewSizes.remove(ratio); |
| 431 | + } |
| 432 | + } |
424 | 433 |
|
425 | 434 | if (!mPreviewSizes.ratios().contains(mAspectRatio)) { |
426 | 435 | mAspectRatio = mPreviewSizes.ratios().iterator().next(); |
@@ -490,24 +499,16 @@ private Size chooseOptimalSize() { |
490 | 499 | surfaceLonger = surfaceWidth; |
491 | 500 | surfaceShorter = surfaceHeight; |
492 | 501 | } |
493 | | - SortedSet<Size> allCandidates = mPreviewSizes.sizes(mAspectRatio); |
494 | | - |
495 | | - // Eliminate candidates that are bigger than Camera2 PREVIEW guarantees |
496 | | - SortedSet<Size> guaranteedCandidates = new TreeSet<>(); |
497 | | - for (Size size: allCandidates) { |
498 | | - if (size.getWidth() <= MAX_PREVIEW_WIDTH && size.getHeight() <= MAX_PREVIEW_HEIGHT) { |
499 | | - guaranteedCandidates.add(size); |
500 | | - } |
501 | | - } |
| 502 | + SortedSet<Size> candidates = mPreviewSizes.sizes(mAspectRatio); |
502 | 503 |
|
503 | 504 | // Pick the smallest of those big enough |
504 | | - for (Size size : guaranteedCandidates) { |
| 505 | + for (Size size : candidates) { |
505 | 506 | if (size.getWidth() >= surfaceLonger && size.getHeight() >= surfaceShorter) { |
506 | 507 | return size; |
507 | 508 | } |
508 | 509 | } |
509 | 510 | // If no size is big enough, pick the largest one. |
510 | | - return guaranteedCandidates.last(); |
| 511 | + return candidates.last(); |
511 | 512 | } |
512 | 513 |
|
513 | 514 | /** |
|
0 commit comments