我开发了一个小应用程序,用于全屏显示相机预览。我为此使用相机 API。
这是活动布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- This is the container for the camera preview screen -->
<FrameLayout android:id="@+id/camera_preview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
当设备处于纵向时,显示会垂直缩放以匹配设备屏幕的高度 - 因此长宽比与本机相机的长宽比不同。这些两张图片可以更好地解释我所说的:
![enter image description here](https://i.stack.imgur.com/lwWT3.jpg)
![enter image description here](https://i.stack.imgur.com/Y1kxa.jpg)
第一张图像是使用本机相机设备拍摄的。
第二张图像是用我的应用程序制作的,相机处于全屏状态 - 图像被倾斜、拉伸以适合屏幕。
我需要相机预览为全屏,无论预览大小如何getSupportedPreviewSizes()
方法且无失真。
有办法做到这一点吗?当相机预览全屏时,有没有办法保持适当的宽高比?我预计这将由操作系统自动完成 - 裁剪图像以匹配请求的分辨率,同时保持宽高比,但这并没有发生。
我已经尝试过SurfaceView
大于显示器(以下问题:将相机预览安装到大于显示屏的 SurfaceView),但在我的情况下不行,因为我正在捕获快照(6 帧/秒),而这些不是用户在屏幕上看到的内容(该帧包含所有相机预览,即使并非全部在屏幕上可见) 。
我在这里发帖:https://www.dropbox.com/s/3d52xt8kazynsae/CameraFullScreen.7z?v=0mcn我所做的整个项目。
任何想法/解决方案对我来说都非常重要。多谢。
=================================================== =====================
由于 ss1271 答案更新:
我将分析一下您上面写的决议三星 Galaxy Ace II.
一、屏幕分辨率: 480x800 - 纵横比 3:5 =0,6
II. getSupportedPreviewSizes
- 我几乎可以肯定这些值来自后置摄像头。以下是这些分辨率的宽高比:
2560x1920 - 0,75
2560x1536 - 0,60
2048x1536 - 0,75
2048x1232 - 0,60
960x720 - 0,75
640x480 - 0,75
所以,你的方法将返回一个Size
对应于2560x1536 or to 2048x1232- 这些具有与屏幕分辨率相同的宽高比,并且使用这些值不会扭曲图片。
对我来说,问题是我不能使用这么大的分辨率,因为我每秒捕获 6 帧,并且这些需要以较低的分辨率保存。
我将在下面展示一些结果三星S2 device:
一、屏幕分辨率: 480 x 800 - 宽高比 3:5 =0,6
二.后置摄像头
a). getSupportedPreviewSizes
:
800 / 480 - 480/800 = 0,60
800 / 450 - 450/800 = 0,56
720 / 480 - 0,66
640 / 480 - 0,75
352 / 288 - 0,81
320 / 240 - 0,75
176 / 144 - 0,81
b).本机相机分辨率:
3264 / 2448 - 0,75 - not full screen
3264 / 1968 - 0,60 - FULL SCREEN (since has the same aspect ratio as device screen)
2048 / 1536 - 0,75 - not full screen
2048 / 1232 - 0,60 - FULL SCREEN (same aspect ratio as device screen)
800 / 480 - 0,60 - FULL SCREEN (same aspect ratio as device screen)
640 / 480 - 0, 75 - not full screen
三.前置摄像头
a). getSupportedPreviewSizes
:
640 / 480 - 0,75
352 / 288 - 0,81
320 / 240 - 0,75
176 / 144 - 0,81
b).本机相机不是全屏,我无法选择分辨率 - 该选项已禁用。
For S2, back camera, I'm wonder why getSupportedPreviewSizes()
method do not return the same resolutions as Native camera does or the ones displayed by native camera are the picture sizes ? I'm wonder why I do not have options like 3264 / 1968, 2048 / 1232 given by getSupportedPreviewSizes()
method ?
:
![enter image description here](https://i.stack.imgur.com/fliSf.jpg)