gpt4 book ai didi

Android 使用 SurfaceTexture TransformMatrix 镜像相机预览

转载 作者:行者123 更新时间:2023-11-29 01:12:49 29 4
gpt4 key购买 nike

我从 Grafika 示例开始,我想用 GlRenderView 渲染相机预览。我的问题是如何修改从 surfacetexture 获得的变换矩阵,以便像使用设备前置摄像头一样获得镜像视频预览:

mDisplaySurface.makeCurrent();
mCameraTexture.updateTexImage();
mCameraTexture.getTransformMatrix(mTmpMatrix);

mFullFrameBlit.drawFrame(mTextureId, mTmpMatrix);

我尝试使用以下行,但我的视频出现了奇怪的效果://应用水平翻转。

// Apply horizontal flip.
android.opengl.Matrix.scaleM(mTmpMatrix, 0, -1, 1, 1);

谢谢大家

最佳答案

我也遇到过这个问题,奇怪的是每次调用drawFrame函数两次都是第一次正确第二次倒过来,像这样:

  mSurfaceTexture.updateTexImage();
mSurfaceTexture.getTransformMatrix(mTmpMatrix);


mDisplaySurface.makeCurrent();
GLES20.glViewport(0, 0, mSurfaceView.getWidth(), mSurfaceView.getHeight());
mFullFrameBlit.drawFrame(mTextureId, mTmpMatrix);//draws in correct direction
mDisplaySurface.swapBuffers();

mOffscreenSurface.makeCurrent();
GLES20.glViewport(0, 0, desiredSize.getWidth(), desiredSize.getHeight());
mFullFrameBlit.drawFrame(mTextureId, mTmpMatrix);//draws upside down
mOffscreenSurface.getPixels();

很好奇为什么会这样......

无论如何,解决方法很简单,只需在 FullFrameRect 类中添加一个 drawFrameFilpped 函数并调用它来绘制翻转图像即可:

    public void drawFrameFlipped(int textureId, float[] texMatrix) {
float[] mMatrix=GlUtil.IDENTITY_MATRIX.clone();//must clone a new one...
Matrix m=new Matrix();
m.setValues(mMatrix);
m.postScale(1,-1);
m.getValues(mMatrix);
//note: the mMatrix is how gl will transform the scene, and
//texMatrix is how the texture to be drawn onto transforms, as @fadden has mentioned
mProgram.draw(mMatrix, mRectDrawable.getVertexArray(), 0,
mRectDrawable.getVertexCount(), mRectDrawable.getCoordsPerVertex(),
mRectDrawable.getVertexStride(),
texMatrix, mRectDrawable.getTexCoordArray(), textureId,
mRectDrawable.getTexCoordStride());
}

然后打电话

    mFullFrameBlit.drawFrameFlipped(mTextureId, mTmpMatrix);

关于Android 使用 SurfaceTexture TransformMatrix 镜像相机预览,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41748038/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com