android - SurfaceTexture.getTransformMatrix 的返回值是什么意思,谁能解释一下?

标签 android matrix crop

各位

我在 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/

相关文章:

python - 矩阵分解如何帮助填充新用户的稀疏效用/评级矩阵?

string - 将字符串拆分为最少数量的字符串,其中每个字母重复奇数次

python - Python 中三角距离矩阵距离的 CSV

css - 如何裁剪引导图像以获得所有图像的宽度 285 和高度 170?

android - 为 ARM/Android 交叉编译大型 C++ 项目 - 问题和注意事项

Android - 测量通过 Intent 打开 Activity 与收到结果之间的时间

java - 如何防止负数/负数

android - 如何通过免提电话播放媒体

javascript - 创建裁剪图像幻灯片

html - slider 裁剪图像而不是调整图像大小