I’m developing application for Android with GLSurfaceView. One moment i have to replace my GLSurfaceView with an image of it in that moment. The question is, how to get an image right? I used this code:
v.setDrawingCacheEnabled(true);
v.measure(View.MeasureSpec.makeMeasureSpec(500, View.MeasureSpec.AT_MOST),
View.MeasureSpec.makeMeasureSpec(500, View.MeasureSpec.AT_MOST));
v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
v.buildDrawingCache(true);
Bitmap b = Bitmap.createBitmap(v.getDrawingCache());
v.setDrawingCacheEnabled(false); // clear drawing cache
return b;
but it always return black bitmap.
Maybe we can make something other then Bitmap (which also can be placed to GLSurfaceView)?
I don’t think it works this way with a
GLSurfaceView. The framebuffer may live inside the GPU, where it’s not directly accessible on the CPU.You can use a framebuffer object to render the image to a texture, then use
glReadPixelsto download the data into a buffer and turn the buffer into aBitmap.