本文介绍了是否可以像 Vertex Shader 和 Fragment Shader 一样为 Android Camera Preview 提供效果,并使用 OpenGLES 保存捕获的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这两个是My VertexShader和Fragment Shader文件:

This two are My VertexShader and Fragment Shader file:

顶点着色器文件:

    attribute vec4 position;
attribute vec4 inputTextureCoordinate;

varying vec2 textureCoordinate;
varying vec4 co;

void main()
{
    gl_Position = position;
    textureCoordinate = inputTextureCoordinate.xy;
    co = inputTextureCoordinate;
}

片段着色器文件:

    uniform sampler2D videoFrame; // the texture with the scene you want to blur
varying mediump vec2 textureCoordinate;
varying mediump vec4 co;
precision mediump float;

vec4 nightVision()
{
    float luminanceThreshold = 0.2; // 0.2
    float colorAmplification = 2.0; // 4.0
    float effectCoverage = 1.0; // 1.0
    vec4 finalColor;
    // Set effectCoverage to 1.0 for normal use.
    if (co.x < effectCoverage)
    {
        vec3 c = texture2D(videoFrame, co.st).rgb;

        float lum = dot(vec3(0.30, 0.59, 0.11), c);
        if (lum < luminanceThreshold) {
            c *= colorAmplification;
        }
        vec3 visionColor = vec3(0.1, 0.95, 0.2);
        finalColor.rgb = (c) * visionColor;
    } else {
        finalColor = texture2D(videoFrame, co.st);
    }
    vec4 sum = vec4(0.0, 0.0, 0.0, 1.0);
    sum.rgb = finalColor.rgb;
    return sum;
}


void main(void)
{
    gl_FragColor = nightVision();
}

现在,我想使用此代码在 Android 相机预览中提供相机预览效果.并且还想保存该效果捕获的图片.

Now, I want to Use this code to give the Camera Preview Effect in Android Camera preview. And also want to save the Picture that captured by that effect.

那么有可能吗???如果是,那么请帮助我一些代码,因为我是使用 Android 相机的 OpenGles 的新手.

So is it possible to do so ???If yes then Please help me with Some code as i am new to OpenGles with Android Camera.

推荐答案

是的,这绝对是可能的.有很多不同的方法来构建它,一个小的代码示例并没有太大帮助.基本思想是将您从相机获得的帧作为纹理提供给 OpenGL.

Yes, it's definitely possible. There are a lot of different approaches to building this, and a small code sample won't really help much. The basic idea is to feed the frames you get from the camera to OpenGL as textures.

查看相机图像作为原生相机取景器顶部的 OpenGL 纹理.源代码应该让您知道如何继续.

Check out Camera image as an OpenGL texture on top of the native camera viewfinder. The source code should give you an idea for how to proceed.

这篇关于是否可以像 Vertex Shader 和 Fragment Shader 一样为 Android Camera Preview 提供效果,并使用 OpenGLES 保存捕获的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 18:02