Android中的相机,如何获得最佳尺寸,预览尺寸,图片尺寸,视图尺寸,图像失真 [英] Camera in Android, how to get best size, preview size, picture size, view size, image distorted

查看:24
本文介绍了Android中的相机,如何获得最佳尺寸,预览尺寸,图片尺寸,视图尺寸,图像失真的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 takepicture 方法时混合来自 OpenGL 和 Android 相机的视图以获取两者的图像时图像失真.查了一下发现相机图片设置为640X480,openGL视图和相机预览都设置为1280x720.

having image distorted when mixing a view from OpenGL and the Android camera to get an image of both when using the takepicture method. I checked and found that the camera picture was set to 640X480 and the openGL view and the camera preview was both set to 1280x720.

所以我将相机图片尺寸设置为 1280x720,结果非常完美.但是我无法在代码中设置大小,因为每个 Android 设备都会有所不同,并且每个设备的预览大小和图片大小的设置都必须从支持的大小列表中选择.

so I set the camera picture size to 1280x720 and the result was perfect. however I can't set the size in code because each Android device will be different and every device the settings for both preview size and picture size have to be selected from a list of supported sizes.

考虑到这里有三个变量,活动布局的屏幕大小、相机预览大小和图片大小,最好的方法是什么.

what is the best way to do this considering that there are three variables here, the screen size of the activity layout, the camera preview size, and the picture size.

最好使用 match_parent 或 fitXY 作为 FrameLayout 大小并且只使用两个变量,预览大小和图片大小?

is it best to use a match_parent or fitXY for the FrameLayout size and only work with two variables, the preview size and picture size?

请注意,预览尺寸和图片尺寸中的一些宽度和高度组合是相同的.比如预览和图片都存在1280 x 720,是否总是两种尺寸都匹配?

notice that several of the width and height combinations in preview sizes and picture sizes are the same. for example 1280 x 720 exists in both preview and picture, is it always the case that there will be matches in both sizes?

 List<Size> previewSizes = mCamera.getParameters().getSupportedPreviewSizes();

 List<Size> imageSizes = mCamera.getParameters().getSupportedPictureSizes();

 // layout in the activity that the cameraView will placed in
 int layoutWidth = frameLayout.getWidth();
 int layoutHeight = frameLayout.getHeight();

例如在一台 Android 平板电脑中测量后,这些是使用的 3 个变量的结果

for example in one Android tablet after measurement these are the results for the 3 variables used

作为测量结果的活动中布局视图组的大小

size of layout viewGroup in activity as result of measurement

 1280 x 736

支持的图片尺寸

 320 x 240
 640 x 480
 1024 x 768
 1280 x 720 << best size in my example to use
 1280 x 768
 1280 x 920
 1600 x 1200
 2048 x 1536
 2560 x 1440
 2560 x 1536
 2560 x 1920  << native resolution of hardware camera

支持的预览尺寸

 176 x 144
 320 x 240
 352 x 288
 480 x 320
 480 x 368
 640 x 480
 800 x 480
 800 x 600
 864 x 480
 864 x 576
 960 x 540
 1280 x 720 << best size in my example to use
 1280 x 768
 1280 x 960

推荐答案

大多数情况下,但并非总是,图片纵横比和预览纵横比之间存在对应关系.您可以放心,其中至少有一些是经典的 4:3 比例(例如 640x480).对 16:9 的支持也很广泛.

Most often, but not always, there is correspondence between picture aspect ratios and preview aspect ratios. You can be assured that at least some of them are classic 4:3 ratios (e.g. 640x480). Support for 16:9 is also widely available.

屏幕可能有不同的纵横比.为了正确填充相机图像,添加黑色边距被广泛接受(YouTube 中使用相同的方法).或者,您可以裁剪相机图像以填满整个屏幕.

The screen may have different aspect ratio. To fill it with a camera image correctly, it is widely accepted to add black margins (same approach is used in YouTube). Alternatively, you may crop the camera image to fill the whole screen.

请注意,屏幕尺寸(如各种设备的技术规格中所报告的)并不总是可用于您的图像显示.例如,系统菜单和标题栏等可能会占用它们的屏幕空间.沉浸式模式在某些设备上可用,其行为取决于系统版本.您可能会期望 Android 的未来发展,例如第二屏支持,将使游戏更加有趣.

Note that the screen size (as reported in tech specs for the variety of devices) is not always actually available for your image display. For example, the system menus, and title bar, etc. may take their share of the screen real estate. The immersive mode is available on some devices, and its behavior depends on the system version. You may expect that future developments of Android, e.g. second screen support, will make the game even more interesting.

所以,你的具体问题的答案:

So, the answers to your specific questions:

最好使用 match_parent 或 fitXY 作为 FrameLayout 大小并且只使用两个变量,预览大小和图片大小? - .

是否总是两种尺寸都匹配? - 是的,但也许这个尺寸不是最佳的.

is it always the case that there will be matches in both sizes? - yes, but maybe this size is not optimal.

即使您的相机支持不同的宽"图片尺寸,1280x720 预览和 2560x1440 图片也可能是最佳匹配,两者都恰好在 16:9.通常,小尺寸的图片质量并不比相同尺寸的预览好很多,所以如果1280x720是你真正需要的,你可以选择保存预览帧.

Even if your camera supports different "wide" picture sizes, 1280x720 preview and 2560x1440 picture may be the best match, both precisely at 16:9. Usually, the quality of picture at small size is not significantly better than preview at that same size, so you may choose to save the preview frame if 1280x720 is what you really need.

如果您可以放弃 takePicture(),您的应用会响应更快.

If you can forgo takePicture(), your app will be much more responsive.

这篇关于Android中的相机,如何获得最佳尺寸,预览尺寸,图片尺寸,视图尺寸,图像失真的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆