Java 相机上的文字不出现,如何使其出现?

Java 相机上的文字不出现,如何使其出现?,java,android-studio,Java,Android Studio,它仅在切换镜头相机时出现一秒钟。我制作了滤镜,我希望滤镜出现在摄像机上,这样用户可以点击他们想要的滤镜,然后点击录制来录制视频。但是它没有显示,我仍然可以点击它,虽然,这是工作,过滤器是好的,只是过滤器的名称/文本没有显示,所以没有人知道他们在那里,除非他们的手指碰巧碰上其中一个文本/名称。我没有得到任何错误,所以我不知道问题出在哪里 如何使文本/名称在摄像机上可见 我的xml: <?xml version="1.0" encoding="utf-8"

它仅在切换镜头相机时出现一秒钟。我制作了滤镜,我希望滤镜出现在摄像机上,这样用户可以点击他们想要的滤镜,然后点击录制来录制视频。但是它没有显示,我仍然可以点击它,虽然,这是工作,过滤器是好的,只是过滤器的名称/文本没有显示,所以没有人知道他们在那里,除非他们的手指碰巧碰上其中一个文本/名称。我没有得到任何错误,所以我不知道问题出在哪里

如何使文本/名称在摄像机上可见

我的xml:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    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:background="@android:color/white"
    android:keepScreenOn="true">

    <ImageView
        android:id="@+id/filter_btn"
        android:layout_width="67dp"
        android:layout_height="53dp"
        android:contentDescription="@string/filter_btn"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/btn_record"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/filter_list"
        app:srcCompat="@drawable/ic_toys" />

    <ImageView
        android:id="@+id/cross"
        android:layout_width="43dp"
        android:layout_height="43dp"
        android:contentDescription="@string/cross"
        app:layout_constraintBottom_toTopOf="@+id/filter_list"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/ic_cross" />

    <ListView
        android:id="@+id/filter_list"
        android:layout_width="119dp"
        android:layout_height="563dp"
        android:visibility="visible"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/btn_record"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:visibility="visible" />

    <com.anisacoding.expriment.VideoEditorFolder.widget.PortraitFrameLayout
        android:id="@+id/wrap_view"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="1.0">


    </com.anisacoding.expriment.VideoEditorFolder.widget.PortraitFrameLayout>

    <ImageView
        android:id="@+id/btn_record"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:contentDescription="@string/record_Video"
        android:text="@string/app_record"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.454"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.926"
        app:srcCompat="@drawable/ic_btn_record" />

    <ImageView
        android:id="@+id/btn_switch_camera"
        android:layout_width="71dp"
        android:layout_height="47dp"
        android:src="@drawable/ic_switch"
        android:text="@string/SWITCH"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.91"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.052"
        app:srcCompat="@drawable/ic_switch"
        android:contentDescription="@string/SWITCH" />

    <ImageView
        android:id="@+id/btn_flash"
        android:layout_width="51dp"
        android:layout_height="40dp"
        android:contentDescription="@string/flash"
        android:text="@string/flash"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.95"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.2"
        app:srcCompat="@drawable/ic_flash" />

    <ImageView
        android:id="@+id/pause_video"
        android:layout_width="90dp"
        android:layout_height="54dp"
        android:contentDescription="@string/record_Video"
        android:text="@string/pause"
        android:visibility="gone"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.454"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.926"
        android:color="#FF0000"
        app:srcCompat="@drawable/ic_stop" />

    <ImageView
        android:id="@+id/music_library3"
        android:layout_width="52dp"
        android:layout_height="47dp"
        android:contentDescription="@string/library_music"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.45"
        app:layout_constraintLeft_toLeftOf="@+id/btn_record"
        app:layout_constraintStart_toStartOf="@+id/guideline18"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.926"
        app:srcCompat="@drawable/ic_music_golibrary" />

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline18"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.7347932" />


    <TextView
        android:id="@+id/timer2"
        android:layout_width="53dp"
        android:layout_height="43dp"
        android:layout_marginStart="25dp"
        android:layout_marginTop="25dp"
        android:text="@string/_2_m"
        android:textStyle="bold"
        android:textSize="20sp"
        android:textColor="#Ff0000"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="@+id/guideline18"
        app:layout_constraintTop_toBottomOf="@+id/btn_flash" />


</androidx.constraintlayout.widget.ConstraintLayout>

2:


代码:

import android.opengl.EGL14;
import android.opengl.EGLConfig;
import android.opengl.EGLContext;
import android.opengl.EGLDisplay;
import android.opengl.EGLExt;
import android.opengl.EGLSurface;
import android.view.Surface;
// Refer : https://android.googlesource.com/platform/cts/+/lollipop-release/tests/tests/media/src/android/media/cts/InputSurface.java
/**
 * Holds state associated with a Surface used for MediaCodec encoder input.
 * <p>
 * The constructor takes a Surface obtained from MediaCodec.createInputSurface(), and uses that
 * to create an EGL window surface.  Calls to eglSwapBuffers() cause a frame of data to be sent
 * to the video encoder.
 */
class EncoderSurface {
    private static final int EGL_RECORDABLE_ANDROID = 0x3142;
    private EGLDisplay eglDisplay = EGL14.EGL_NO_DISPLAY;
    private EGLContext eglContext = EGL14.EGL_NO_CONTEXT;
    private EGLSurface eglSurface = EGL14.EGL_NO_SURFACE;
    private Surface surface;
    /**
     * Creates an EncoderSurface from a Surface.
     */
    EncoderSurface(Surface surface) {
        if (surface == null) {
            throw new NullPointerException();
        }
        this.surface = surface;
        eglSetup();
    }
    /**
     * Prepares EGL.  We want a GLES 2.0 context and a surface that supports recording.
     */
    private void eglSetup() {
        eglDisplay = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
        if (eglDisplay == EGL14.EGL_NO_DISPLAY) {
            throw new RuntimeException("unable to get EGL14 display");
        }
        int[] version = new int[2];
        if (!EGL14.eglInitialize(eglDisplay, version, 0, version, 1)) {
            eglDisplay = null;
            throw new RuntimeException("unable to initialize EGL14");
        }
        // Configure EGL for recordable and OpenGL ES 2.0.  We want enough RGB bits
        // to minimize artifacts from possible YUV conversion.
        int[] attribList = {
                EGL14.EGL_RED_SIZE, 8,
                EGL14.EGL_GREEN_SIZE, 8,
                EGL14.EGL_BLUE_SIZE, 8,
                EGL14.EGL_RENDERABLE_TYPE, EGL14.EGL_OPENGL_ES2_BIT,
                EGL_RECORDABLE_ANDROID, 1,
                EGL14.EGL_NONE
        };
        EGLConfig[] configs = new EGLConfig[1];
        int[] numConfigs = new int[1];
        if (!EGL14.eglChooseConfig(eglDisplay, attribList, 0, configs, 0, configs.length,
                numConfigs, 0)) {
            throw new RuntimeException("unable to find RGB888+recordable ES2 EGL config");
        }
        // Configure context for OpenGL ES 2.0.
        int[] attrib_list = {
                EGL14.EGL_CONTEXT_CLIENT_VERSION, 2,
                EGL14.EGL_NONE
        };
        eglContext = EGL14.eglCreateContext(eglDisplay, configs[0], EGL14.EGL_NO_CONTEXT,
                attrib_list, 0);
        checkEglError("eglCreateContext");
        if (eglContext == null) {
            throw new RuntimeException("null context");
        }
        // Create a window surface, and attach it to the Surface we received.
        int[] surfaceAttribs = {
                EGL14.EGL_NONE
        };
        eglSurface = EGL14.eglCreateWindowSurface(eglDisplay, configs[0], surface,
                surfaceAttribs, 0);
        checkEglError("eglCreateWindowSurface");
        if (eglSurface == null) {
            throw new RuntimeException("surface was null");
        }
    }
    /**
     * Discard all resources held by this class, notably the EGL context.  Also releases the
     * Surface that was passed to our constructor.
     */
    public void release() {
        if (eglDisplay != EGL14.EGL_NO_DISPLAY) {
            EGL14.eglDestroySurface(eglDisplay, eglSurface);
            EGL14.eglDestroyContext(eglDisplay, eglContext);
            EGL14.eglReleaseThread();
            EGL14.eglTerminate(eglDisplay);
        }
        surface.release();
        eglDisplay = EGL14.EGL_NO_DISPLAY;
        eglContext = EGL14.EGL_NO_CONTEXT;
        eglSurface = EGL14.EGL_NO_SURFACE;
        surface = null;
    }
    /**
     * Makes our EGL context and surface current.
     */
    void makeCurrent() {
        if (!EGL14.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)) {
            throw new RuntimeException("eglMakeCurrent failed");
        }
    }
    /**
     * Calls eglSwapBuffers.  Use this to "publish" the current frame.
     */
    void swapBuffers() {
        EGL14.eglSwapBuffers(eglDisplay, eglSurface);
    }
    /**
     * Sends the presentation time stamp to EGL.  Time is expressed in nanoseconds.
     */
    void setPresentationTime(long nsecs) {
        EGLExt.eglPresentationTimeANDROID(eglDisplay, eglSurface, nsecs);
    }
    /**
     * Checks for EGL errors.
     */
    private void checkEglError(String msg) {
        int error;
        if ((error = EGL14.eglGetError()) != EGL14.EGL_SUCCESS) {
            throw new RuntimeException(msg + ": EGL error: 0x" + Integer.toHexString(error));
        }
    }
}
导入android.opengl.EGL14;
导入android.opengl.EGLConfig;
导入android.opengl.EGLContext;
导入android.opengl.EGLDisplay;
导入android.opengl.EGLExt;
导入android.opengl.EGLSurface;
导入android.view.Surface;
//参考:https://android.googlesource.com/platform/cts/+/棒棒糖发布/tests/tests/media/src/android/media/cts/InputSurface.java
/**
*保存与用于MediaCodec编码器输入的曲面关联的状态。
*
*构造函数获取从MediaCodec.createInputSurface()获得的曲面,并使用该曲面
*创建EGL窗曲面的步骤。调用eglSwapBuffers()会导致发送一帧数据
*到视频编码器。
*/
类编码器曲面{
私有静态最终int EGL_可记录_ANDROID=0x3142;
专用EGLDisplay EGLDisplay=EGL14.EGL\u无显示;
private EGLContext EGLContext=EGL14.EGL\u NO\u CONTEXT;
专用EGL曲面EGL曲面=EGL14.EGL_无_曲面;
私人表面;
/**
*从曲面创建编码器曲面。
*/
编码器表面(表面){
如果(曲面==null){
抛出新的NullPointerException();
}
这个表面=表面;
eglSetup();
}
/**
*准备EGL。我们需要一个GLE2.0上下文和一个支持录制的表面。
*/
私有void eglSetup(){
eglDisplay=EGL14.eglGetDisplay(EGL14.EGL\u默认显示);
if(eglDisplay==EGL14.EGL\u无显示){
抛出新的RuntimeException(“无法获取EGL14显示”);
}
int[]版本=新int[2];
if(!EGL14.eglInitialize(eglDisplay,version,0,version,1)){
eglDisplay=null;
抛出新的RuntimeException(“无法初始化EGL14”);
}
//为可记录和OpenGL ES 2.0配置EGL。我们需要足够的RGB位
//尽量减少可能的YUV转换产生的瑕疵。
int[]属性列表={
EGL14.EGL_红色_尺寸,8,
EGL14.EGL_绿色_尺寸,8,
EGL14.EGL_蓝色_尺寸,8,
EGL14.EGL_可渲染类型,EGL14.EGL_OPENGL_ES2_位,
EGL_可记录机器人,1,
EGL14.EGL_无
};
EGLConfig[]configs=新的EGLConfig[1];
int[]numconfig=newint[1];
如果(!EGL14.eglChooseConfig)(eglDisplay,attribList,0,configs,0,configs.length,
numconfig,0){
抛出新的RuntimeException(“找不到RGB888+可记录ES2 EGL配置”);
}
//为OpenGL ES 2.0配置上下文。
int[]属性列表={
EGL14.EGL_上下文_客户端_版本,2,
EGL14.EGL_无
};
eglContext=EGL14.eglCreateContext(eglDisplay,configs[0],EGL14.EGL\u NO\u CONTEXT,
属性列表,0);
checkEglError(“eglCreateContext”);
if(eglContext==null){
抛出新的RuntimeException(“空上下文”);
}
//创建一个窗口曲面,并将其附着到我们收到的曲面。
int[]表面纹理={
EGL14.EGL_无
};
eglSurface=EGL14.EGLCreateWindowsSurface(eglDisplay,配置[0],表面,
表面粗糙度,0);
CheckLerror(“EGLCreateWindowsSurface”);
if(eglSurface==null){
抛出新的运行时异常(“表面为空”);
}
}
/**
*放弃此类持有的所有资源,尤其是EGL上下文
*传递给构造函数的曲面。
*/
公开无效释放(){
if(eglDisplay!=EGL14.EGL\u无显示){
EGL14.eglDestroySurface(eglDisplay,eglSurface);
EGL14.eglDestroyContext(eglDisplay,eglContext);
EGL14.eglReleaseThread();
EGL14.eglTerminate(eglDisplay);
}
表面。释放();
eglDisplay=EGL14.EGL\u无显示;
eglContext=EGL14.EGL\u无上下文;
EGL表面=EGL14.EGL_无表面;
表面=零;
}
/**
*使我们的EGL环境和表面最新。
*/
void makeCurrent(){
if(!EGL14.eglmakefurrent(eglDisplay,eglSurface,eglSurface,eglContext)){
抛出新的运行时异常(“eglMakeCurrent失败”);
}
}
/**
*调用eglSwapBuffers。使用它“发布”当前帧。
*/
无效交换缓冲区(){
EGL14.eglSwapBuffers(eglDisplay,eglSurface);
}
/**
*将表示时间戳发送到EGL。时间以纳秒表示。
*/
void setPresentationTime(长NSEC){
EGLExt.eglPresentationTimeANDROID(eglDisplay、eglSurface、nsecs);
}
/**
*检查EGL错误。
*/
私有无效校验错误(字符串消息){
整数误差;
if((error=EGL14.eglGetError())!=EGL14.EGL_成功){
抛出新的运行时异常(msg+“:EGL错误:0x”+整数.toHexString(错误));
}
}
}
import android.opengl.EGL14;
import android.opengl.EGLConfig;
import android.opengl.EGLContext;
import android.opengl.EGLDisplay;
import android.opengl.EGLExt;
import android.opengl.EGLSurface;
import android.view.Surface;
// Refer : https://android.googlesource.com/platform/cts/+/lollipop-release/tests/tests/media/src/android/media/cts/InputSurface.java
/**
 * Holds state associated with a Surface used for MediaCodec encoder input.
 * <p>
 * The constructor takes a Surface obtained from MediaCodec.createInputSurface(), and uses that
 * to create an EGL window surface.  Calls to eglSwapBuffers() cause a frame of data to be sent
 * to the video encoder.
 */
class EncoderSurface {
    private static final int EGL_RECORDABLE_ANDROID = 0x3142;
    private EGLDisplay eglDisplay = EGL14.EGL_NO_DISPLAY;
    private EGLContext eglContext = EGL14.EGL_NO_CONTEXT;
    private EGLSurface eglSurface = EGL14.EGL_NO_SURFACE;
    private Surface surface;
    /**
     * Creates an EncoderSurface from a Surface.
     */
    EncoderSurface(Surface surface) {
        if (surface == null) {
            throw new NullPointerException();
        }
        this.surface = surface;
        eglSetup();
    }
    /**
     * Prepares EGL.  We want a GLES 2.0 context and a surface that supports recording.
     */
    private void eglSetup() {
        eglDisplay = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
        if (eglDisplay == EGL14.EGL_NO_DISPLAY) {
            throw new RuntimeException("unable to get EGL14 display");
        }
        int[] version = new int[2];
        if (!EGL14.eglInitialize(eglDisplay, version, 0, version, 1)) {
            eglDisplay = null;
            throw new RuntimeException("unable to initialize EGL14");
        }
        // Configure EGL for recordable and OpenGL ES 2.0.  We want enough RGB bits
        // to minimize artifacts from possible YUV conversion.
        int[] attribList = {
                EGL14.EGL_RED_SIZE, 8,
                EGL14.EGL_GREEN_SIZE, 8,
                EGL14.EGL_BLUE_SIZE, 8,
                EGL14.EGL_RENDERABLE_TYPE, EGL14.EGL_OPENGL_ES2_BIT,
                EGL_RECORDABLE_ANDROID, 1,
                EGL14.EGL_NONE
        };
        EGLConfig[] configs = new EGLConfig[1];
        int[] numConfigs = new int[1];
        if (!EGL14.eglChooseConfig(eglDisplay, attribList, 0, configs, 0, configs.length,
                numConfigs, 0)) {
            throw new RuntimeException("unable to find RGB888+recordable ES2 EGL config");
        }
        // Configure context for OpenGL ES 2.0.
        int[] attrib_list = {
                EGL14.EGL_CONTEXT_CLIENT_VERSION, 2,
                EGL14.EGL_NONE
        };
        eglContext = EGL14.eglCreateContext(eglDisplay, configs[0], EGL14.EGL_NO_CONTEXT,
                attrib_list, 0);
        checkEglError("eglCreateContext");
        if (eglContext == null) {
            throw new RuntimeException("null context");
        }
        // Create a window surface, and attach it to the Surface we received.
        int[] surfaceAttribs = {
                EGL14.EGL_NONE
        };
        eglSurface = EGL14.eglCreateWindowSurface(eglDisplay, configs[0], surface,
                surfaceAttribs, 0);
        checkEglError("eglCreateWindowSurface");
        if (eglSurface == null) {
            throw new RuntimeException("surface was null");
        }
    }
    /**
     * Discard all resources held by this class, notably the EGL context.  Also releases the
     * Surface that was passed to our constructor.
     */
    public void release() {
        if (eglDisplay != EGL14.EGL_NO_DISPLAY) {
            EGL14.eglDestroySurface(eglDisplay, eglSurface);
            EGL14.eglDestroyContext(eglDisplay, eglContext);
            EGL14.eglReleaseThread();
            EGL14.eglTerminate(eglDisplay);
        }
        surface.release();
        eglDisplay = EGL14.EGL_NO_DISPLAY;
        eglContext = EGL14.EGL_NO_CONTEXT;
        eglSurface = EGL14.EGL_NO_SURFACE;
        surface = null;
    }
    /**
     * Makes our EGL context and surface current.
     */
    void makeCurrent() {
        if (!EGL14.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)) {
            throw new RuntimeException("eglMakeCurrent failed");
        }
    }
    /**
     * Calls eglSwapBuffers.  Use this to "publish" the current frame.
     */
    void swapBuffers() {
        EGL14.eglSwapBuffers(eglDisplay, eglSurface);
    }
    /**
     * Sends the presentation time stamp to EGL.  Time is expressed in nanoseconds.
     */
    void setPresentationTime(long nsecs) {
        EGLExt.eglPresentationTimeANDROID(eglDisplay, eglSurface, nsecs);
    }
    /**
     * Checks for EGL errors.
     */
    private void checkEglError(String msg) {
        int error;
        if ((error = EGL14.eglGetError()) != EGL14.EGL_SUCCESS) {
            throw new RuntimeException(msg + ": EGL error: 0x" + Integer.toHexString(error));
        }
    }
}