Android 相机在横向模式下拉伸
我正在编写的应用程序需要相机功能。 因此,为了了解如何操作相机,我遵循了以下脚本:
我有将活动放入我的清单中,将其屏幕方向设置为横向模式。
我遇到的问题是,当相机横向放置时(因此我将 Galaxy Tab P1000 横向放置),视图会被拉伸。
为了更具体地说明我的脚本,我使用了 Google 制作的代码的精确副本。可以在 android-sdk\samples\android-8\ApiDemos\src\com\example\android\apis\graphics\ 中找到,
文件本身名为 CameraPreview。
我真的不知道为什么屏幕看起来这么拉伸。当然,格式很奇怪而且不是方形的,但是,当使用设备上安装的默认相机应用程序时,它根本不会变形。当我侧握该相机并稍微移动相机时,图像就会变形。
我所做的是:我拿着我的 Galaxy 标签拍摄一个物体(在本例中为笔记本电脑)的照片,然后用我的 Galaxy 手机拍了一张照片。在 Galaxy 上,我在我正在制作的应用程序中打开了相机屏幕。这对于两个图像都很重要。一张我横向拿着,一张我纵向拿着。照片有点不清楚,但你可以看到在风景照片中,相机变得非常宽。
The app I'm writing requires camera functionality.
So to learn about how to operate the camera, I followed this script:
I have put the activity in my manifest, set the screen orientation for it on landscape mode.
The problem I'm having is, when the camera is held sideways (so I hold my Galaxy Tab P1000 in landscape position) the view is stretched out.
To be more specific about my script, I used an exact copy of code that Google made. It can be found in the android-sdk\samples\android-8\ApiDemos\src\com\example\android\apis\graphics\
The file itself is called CameraPreview.
I really have no clue why the screen looks so stretched. Of course, the format is weird and not square, but still, when using the default camera app installed on the device, it doesn't deform at all. This camera deforms the image when I hold it sideways and move the camera even a little.
What I did was: I held my galaxy tab to take a picture of an object (laptop in this case) then took a picture with my phone of my Galaxy. On the Galaxy I have the camera screen open in the app i'm making. This counts for both images. One I hold sideways and one I hold in portrait view. The pics are a bit unclear but you can see that in the landscape picture, the camera has become massively wide.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我昨天遇到了同样的问题。在研究“相机”来源后,我发现了相机预览被拉伸的原因。
原因是:SurfaceView 的宽高比(宽度/高度)必须与预览参数中使用的 Camera.Size 宽高比相同。如果长宽比不一样,你就会得到拉伸的图像。
因此,最快的解决方法是将 SurfaceView 设置为 320px x 240px 之类的大小 - 来自Parameters.getSupportedPreviewSizes() 的最小支持大小。
另外,您可以查看Camera标准应用程序源代码,它使用自定义布局来控制SurfaceView大小(请参阅PreviewFrameLayout.java,onMeasure()函数)。
使用
git clone https://android.googlesource.com/platform/packages/apps/Camera.git
获取相机源。
I faced the same problem yesterday. After a researching "Camera" sources I found a reason for camera preview being stretched.
The reason is: SurfaceView aspect ratio (width/height) MUST be same as Camera.Size aspect ratio used in preview parameters. And if aspect ratio is not the same, you've got stretched image.
So, the fastest workaround is to set SurfaceView to size like 320px x 240px - smallest supported size from Parameters.getSupportedPreviewSizes().
Also, you can look at Camera standard application sources, it uses the custom layout for controlling the SurfaceView size (see PreviewFrameLayout.java, onMeasure() function).
Use
git clone https://android.googlesource.com/platform/packages/apps/Camera.git
to get Camera sources.
您只需要
getSupportedPreviewSizes()
并将其保存到List
:我希望这对您有帮助。
You need only
getSupportedPreviewSizes()
and save it to aList
:I hope this helps you.