从GLSurfaceView中拿到图片。
因为项目中视频拍摄使用第三方sdk,但是图片拍摄需要自己实现,而sdk的视频预览使用的是GLSurfaceview,SurfaceView 和 GLSurfaceView是自己独立渲染画面,不同于普通view。所以不能使用普通的view截图方式,在stackoverflow上找到的答案是这样的:
private Bitmap createBitmapFromGLSurface(int x, int y, int w, int h, GL10 gl)
throws OutOfMemoryError {
int bitmapBuffer[] = new int[w * h];
int bitmapSource[] = new int[w * h];
IntBuffer intBuffer = IntBuffer.wrap(bitmapBuffer);
intBuffer.position(0);
try {
gl.glReadPixels(x, y, w, h, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, intBuffer);
int offset1, offset2;
for (int i = 0; i < h; i++) {
offset1 = i * w;
offset2 = (h - i - 1) * w;
for (int j = 0; j < w; j++) {
int texturePixel = bitmapBuffer[offset1 + j];
in