shadercam

Simple OpenGL Shaders with the camera2 apis in Android 5.0+

examples

Check out shadercam-example here for basic usage.

Also, shadercam was built for usage with a couple Android Experiments:

permissions

updated 9/14/15

We've added a PermissionsHelper fragment to make handling Android M's new permissions model a bit easier.

Refer to the example applications MainActivity.java for implementation specifics.

usage

Import shadercam in your build.gradle file:

compile project(':shadercam')

or

compile 'com.androidexperiments:shadercam:1.1.0'

shadercam comes with a simple implementation of the camera2 apis called CameraFragment, which only requires that you add a TextureView to your layout.

private void setCameraFragment() {
    mCameraFragment = CameraFragment.getInstance();
    mCameraFragment.setCameraToUse(CameraFragment.CAMERA_PRIMARY); //or CAMERA_BACK
    mCameraFragment.setTextureView(mTextureView); //the TextureView we added to our layout

    //add fragment to our setup and let it work its magic
    getSupportFragmentManager().beginTransaction()
        .add(mCameraFragment, TAG_CAMERA_FRAGMENT) //any tag is fine if u want to access later
        .commit();
}

Once your CameraFragment is setup, we need to wait until our TextureView is ready to create our CameraRenderer.

public void onResume() {
    if(!mTextureView.isAvailable())
        mTextureView.setSurfaceTextureListener(mTextureListener);
    else
        setReady(mTextureView.getSurfaceTexture(), mTextureView.getWidth(), mTextureView.getHeight());
}

Our texture listener is your normal, every day TextureView.SurfaceTextureListener that will also call our setReady method that will create our renderer. Now all you have to do is extend CameraRenderer to do anything you want with the video feed!

private void setReady(SurfaceTexture surface, int width, int height) {
    mRenderer = new ExampleRenderer(this, surface, mCameraFragment, width, height);
    mRenderer.setOnRendererReadyListener(this);
    mRenderer.start();

    //initial config if needed
    mCameraFragment.configureTransform(width, height);
}

Check out MainActivity and ExampleRenderer in shadercam-example for more in depth explanations and details.

more info

If you make something cool with shadercam, let us know by heading over to Android Experiments and submitting your experiment!

Report any issues here - we love pull requests!

license

Copyright 2015 Google Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.


shadercam

Android 5.0 +中的 camera2 apis的简单OpenGL着色器

p>

示例

请查看 shadercam-example ,以获得基本用法。

此外, shadercam 是为了使用几个Android实验而构建的:

权限

更新9/14/15

我们添加了 PermissionsHelper 片段使Android M的新权限模型更容易处理。

请参阅示例应用程序 MainActivity.java 有关实施细节。

用法

build.gradle 文件中导入 shadercam

compile project(':shadercam')

compile 'com.androidexperiments:shadercam:1.1.0'

shadercam 附带了一个简单实现的camera2 apis,名为 CameraFragment ,只有 要求您在布局中添加 TextureView

private void setCameraFragment() {
    mCameraFragment = CameraFragment.getInstance();
    mCameraFragment.setCameraToUse(CameraFragment.CAMERA_PRIMARY); //or CAMERA_BACK
    mCameraFragment.setTextureView(mTextureView); //the TextureView we added to our layout

//add fragment to our setup and let it work its magic
getSupportFragmentManager().beginTransaction()
    .add(mCameraFragment, TAG_CAMERA_FRAGMENT) //any tag is fine if u want to access later
    .commit();

}

一旦您的CameraFragment设置完成,我们需要等到我们的 TextureView 准备好创建 我们的 CameraRenderer

public void onResume() {
    if(!mTextureView.isAvailable())
        mTextureView.setSurfaceTextureListener(mTextureListener);
    else
        setReady(mTextureView.getSurfaceTexture(), mTextureView.getWidth(), mTextureView.getHeight());
}

我们的纹理监听器是你的普通的,每天 TextureView.SurfaceTextureListener 也将调用我们的 setReady 方法来创建我们的渲染器。 现在,您只需扩展 CameraRenderer 即可使用视频Feed进行任何操作!

private void setReady(SurfaceTexture surface, int width, int height) {
    mRenderer = new ExampleRenderer(this, surface, mCameraFragment, width, height);
    mRenderer.setOnRendererReadyListener(this);
    mRenderer.start();

//initial config if needed
mCameraFragment.configureTransform(width, height);

}

shadercam-example 中查看<代码> MainActivity 和 ExampleRenderer ,以获得更多深入的解释和细节。

更多信息

如果您使用shadercam做一些很酷的事情,请转到 Android实验并提交实验,让我们知道!

报告任何问题这里 - 我们喜欢拉请求!

许可证

Copyright 2015 Google Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.




相关问题推荐