问题描述
有从混合OpenGL和Android相机视图时得到使用takepicture方法时两者的图像的图像失真。我查了一下,发现摄像头的图片设置为640X480和OpenGL的观点和摄像机preVIEW既设置为1280×720。
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.
所以我设置的摄像机图像大小为1280×720,结果是完美的。不过,我不能设置在code的大小,因为每一个Android设备将是不同的,每个装置的设置两个preVIEW尺寸和图像尺寸必须从支持的尺寸列表中选择。
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.
什么是要做到这一点考虑到有三个变量这里,活性布局,相机preVIEW大小的屏幕尺寸的最佳方式,和图像尺寸。
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尺寸和只有两个变量工作,preVIEW尺寸和图像尺寸?
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?
的通知那几个在preVIEW尺寸和画面尺寸的宽度和高度的组合是相同的。例如1280×720存在于两个preVIEW和图片,是它总是如此将有在两种尺寸匹配?
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
布局的ViewGroup的活动规模作为测量结果
size of layout viewGroup in activity as result of measurement
1280 x 736
支持的图片尺寸
supported picture sizes
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
支持preVIEW尺寸
supported preview sizes
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
推荐答案
通常,但不总是,存在画面的纵横比和preVIEW长宽比之间的对应关系。你可以放心,至少其中一些是经典的4:3比例(如640×480)。支持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尺寸和只有两个变量工作,preVIEW大小和画面尺寸 - 否。
是它总是这样会有两种尺寸的匹配的 - 是,但也许这个尺寸是不是最优的。
is it always the case that there will be matches in both sizes? - yes, but maybe this size is not optimal.
即使你的相机支持不同的宽的画面尺寸, 1280×720 骨节病> preVIEW和 2560×1440 骨节病>图片可能是最好的比赛,无论是precisely在 16:9
。通常情况下,画面的尺寸小质量不显著好于preVIEW以相同的尺寸,所以你可以选择保存的 preVIEW帧的,如果 1280×720
是你真正需要的。
Even if your camera supports different "wide" picture sizes, preview and 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中,如何获得最佳尺寸,preVIEW大小,图片大小,浏览尺寸,图像失真的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!