在开发视频相关的app时,采用了TextureView作为图像预览的控件,据说这个控件比surfaceView好。那么问题来了我摄像头获取到的图像在TextureView中显示时被拉宽了。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<TextureView
android:id="@+id/texture_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout >
上面是我的界面布局,可以看出,我想把图像铺满整个界面,但是实际的效果是这样的:
很明显,画面中的文字被拉伸了,而且上下有空白,不应该啊。
到处查也没有直接说的,自己就随便改改参数了。
本来:
textureView.setRotation(90); //设置预览角度,并不改变获取到的原始数据方向(与Camera.setDisplayOrientation(0)相同)
在这里设置图像旋转90度,后面的括号还“贴心”提示了。后来就换了后面括号里的显示方法
mCamera.setDisplayOrientation(90);// 设置预览角度,并不改变获取到的原始数据方向
然后就
这不就是我想要的结果吗?说好的一样呢?
算了算了,能改过就是个好人,不生气!