如何旋转textureView显示相机preVIEW [英] how to rotate textureView to show a cameraPreview
问题描述
我用摄像机2 API来显示相机preVIEW,我锁定lanscape屏幕的方向,我的问题是,我想旋转textureview以显示正确的相机preVIEW,当我旋转使用该方法setRotation,它变得更小。我搜索堆栈,但所有的解决方案都相对于摄像头(第一个API),所以有旋转textureView的解决方案。
I use the camera2 api to show a camerapreview, and i lock the screen orientation on lanscape, my problem is that i want to rotate the textureview to display the correct camerapreview, when i rotate it using the method setRotation, it becomes smaller. I search on stack but all solutions are relative to camera(first api) so is there a solution to rotate the textureView.
推荐答案
您可以添加一个旋转到TextureView的矩阵。举一个例子,请参见 Grafika的玩电影活动,它发送一个视频去$ C $的输出CR到TextureView(相同的基本原则,相机preVIEW)。
You can add a rotation to the TextureView's matrix. For an example, see Grafika's "play movie activity", which sends the output of a video decoder to a TextureView (same basic principles as Camera preview).
如果你看一下<一个href=\"https://github.com/google/grafika/blob/master/src/com/android/grafika/PlayMovieActivity.java#L211\"相对=nofollow> adjustAspectRatio()
你可以看到它调节输出的位置(翻译)和规模相匹配的视频的显示比例。还有一个注释掉 postRotate()
通话将旋转输出10度。
If you look at adjustAspectRatio()
you can see it adjusting the position (translation) and scale of the output to match the video's aspect ratio. There's also a commented out postRotate()
call that would rotate the output 10 degrees.
请注意这是旋转视图中的视频帧,而不是视图本身。
Note this is rotating the video frame within the View, not the View itself.
这篇关于如何旋转textureView显示相机preVIEW的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!