各位
我在 Android 中使用 SurfaceTexture 但我无法理解它的 API:getTransformMatrix(float[] mtx),API 文档如下:
/**
* Retrieve the 4x4 texture coordinate transform matrix associated with the texture image set by
* the most recent call to updateTexImage.
*
* This transform matrix maps 2D homogeneous texture coordinates of the form (s, t, 0, 1) with s
* and t in the inclusive range [0, 1] to the texture coordinate that should be used to sample
* that location from the texture. Sampling the texture outside of the range of this transform
* is undefined.
*
* The matrix is stored in column-major order so that it may be passed directly to OpenGL ES via
* the glLoadMatrixf or glUniformMatrix4fv functions.
*
* @param mtx the array into which the 4x4 matrix will be stored. The array must have exactly
* 16 elements.
*/
看完了,真不知道怎么用。 我想在 SurfaceTexture 中裁剪纹理图像并将 SurfaceTexture obj 提供给 EGLSurface 对象。
比如原图是320*720(w*h),我希望新图是320*240(w*h)
要实现这个功能应该怎么做? 4 * 4矩阵可以帮助我吗? 4*4矩阵怎么办?
最佳答案
这是一个与 GLES 兼容的变换矩阵,可用于旋转或翻转图像。一般来说,您只需将它传递给任何要渲染 SurfaceTexture 创建的 GLES 纹理的东西。
您可以在 Grafika 中查看它的示例;在 ContinuousCaptureActivity.java、CameraCaptureActivity.java 和 TextureMovieEncoder.java 中搜索它。
矩阵可用于执行各种affine transformations ,例如旋转和缩放,但不能用于裁剪图像。
矩阵包含在 API 中,因为有时输入源处于“错误”方向。系统不会花费 CPU 或 GPU 周期来重新排列像素,而是随每一帧一起发送一个矩阵。如果框架内容按原样正确,矩阵将是恒等的。如果是颠倒的,将提供一个经过适当修正的矩阵。
关于android - SurfaceTexture.getTransformMatrix 的返回值是什么意思,谁能解释一下?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30595493/