我要从一个主界面中,获取其中的一个子窗口如图中的人物镜(surfaceview)显示的内容保存成图片!他是一个摄像镜头所显示的动态的图像。朋友说可以用opengl 中glreadpixels 方法实现 。但是我按照网上的方法进行操作结果只是获取整个页面显示的图像,子窗口内容全为黑黑的一片。 所以想请问一下怎么取得该子窗口surfaceview的缓冲数据???谢谢
以下是我初始化EGL的代码,是哪些参数用得不对吗还是?请大神指点,感激不尽!
public static GL10 gl;
private int[] version = new int[2];
EGLConfig[] configs = new EGLConfig[1];
int[] num_config = new int[1];
//EglchooseConfig used this config
int[] configSpec ={
EGL10.EGL_SURFACE_TYPE, EGL10.EGL_PBUFFER_BIT,
EGL10.EGL_RED_SIZE, 8,
EGL10.EGL_GREEN_SIZE, 8,
EGL10.EGL_BLUE_SIZE, 8,
EGL10.EGL_ALPHA_SIZE, 8,
EGL10.EGL_NONE
};
//eglCreatePbufferSurface used this config
int attribListPbuffer[] = {
EGL10.EGL_WIDTH, 480,
EGL10.EGL_HEIGHT, 800,
EGL10.EGL_NONE
};
private void initEGL()
{
EGL10 mEgl = (EGL10)EGLContext.getEGL();
EGLDisplay mEglDisplay = mEgl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
mEgl.eglInitialize(mEglDisplay, version);
mEgl.eglChooseConfig(mEglDisplay, configSpec, configs, 1, num_config);
EGLConfig mEglConfig = configs[0];
EGLContext mEglContext = mEgl.eglCreateContext(mEglDisplay, mEglConfig,
EGL10.EGL_NO_CONTEXT,
null);
if (mEglContext == EGL10.EGL_NO_CONTEXT)
{
//mEgl.eglDestroySurface(mEglDisplay, mEglSurface);
Log.d("ERROR:", "no CONTEXT");
}
//注意这个attribListPbuffer,属性表
EGLSurface mEglPBSurface = mEgl.eglCreatePbufferSurface(mEglDisplay, mEglConfig, attribListPbuffer);
if (mEglPBSurface == EGL10.EGL_NO_SURFACE)
{
//mEgl.eglDestroySurface(mEglDisplay, mEglPBSurface);
int ec = mEgl.eglGetError();
if (ec == EGL10.EGL_BAD_DISPLAY)
{
Log.d("ERROR:", "EGL_BAD_DISPLAY");
}
if (ec == EGL10.EGL_BAD_DISPLAY)
{
Log.d("ERROR:", "EGL_BAD_DISPLAY");
}
if (ec == EGL10.EGL_NOT_INITIALIZED)
{
Log.d("ERROR:", "EGL_NOT_INITIALIZED");
}
if (ec == EGL10.EGL_BAD_CONFIG)
{
Log.d("ERROR:", "EGL_BAD_CONFIG");
}
if (ec == EGL10.EGL_BAD_ATTRIBUTE)
{
Log.d("ERROR:", "EGL_BAD_ATTRIBUTE");
}
if (ec == EGL10.EGL_BAD_ALLOC)
{
Log.d("ERROR:", "EGL_BAD_ALLOC");
}
if (ec == EGL10.EGL_BAD_MATCH)
{
Log.d("ERROR:", "EGL_BAD_MATCH");
}
}
if (!mEgl.eglMakeCurrent(mEglDisplay, mEglPBSurface, mEglPBSurface,
mEglContext))//这里mEglPBSurface,意思是画图和读图都是从mEglPbSurface开始
{
Log.d("ERROR:", "bind failed ECODE:"+mEgl.eglGetError());
}
gl = (GL10) mEglContext.getGL();
}