JME to Bitmap/byte array

Is it possible to achieve the drawingcache or bytearrary of the entire view?



I tried various things without luck.

And i really need to be able to take screenshots of the surfaceview, with the sceen

Yes it is possible - look into the SceneProcessor topic or search for ScreenshotAppState, these things are designed to let you access the whole FrameBuffer (or take some screenshots of them).



EDIT: I hope this is what you asked for: https://code.google.com/p/jmonkeyengine/source/browse/trunk/engine/src/core/com/jme3/post/SceneProcessor.java

@cmur2 said:
Yes it is possible - look into the SceneProcessor topic or search for ScreenshotAppState, these things are designed to let you access the whole FrameBuffer (or take some screenshots of them).

EDIT: I hope this is what you asked for: https://code.google.com/p/jmonkeyengine/source/browse/trunk/engine/src/core/com/jme3/post/SceneProcessor.java

I looked at the ScreenshotAppState and capturing the framebuffer.
The problem is that this is not implemented in Android.
If you look in OGLESShaderRenderer, you will find this:
[java]public void readFrameBuffer(FrameBuffer fb, ByteBuffer byteBuf) {
logger.warning("readFrameBuffer is not supported.");
}[/java]
This kinda gets in the way of capturing the screen ^^

Ah yes, than this was the problem on Android… I remember vaguely that there are possibilities to capture the screen application independent on Android but I’m not an Android expert.

can we except a hotfix any time soon?

bump

Tried with “setDrawingCacheEnabled(true)”

[java]View main = view.getRootView();

main.setDrawingCacheEnabled(true);

bitmap = Bitmap.createBitmap(main.getDrawingCache());

main.setDrawingCacheEnabled(false);[/java]

Problem is, this gets me a bitmap with all the XML elements, except the JME scene.

In place of the JME scene, its just all black, but the other XML elements show up just fine.

Finally got it working. Had to add a few lines to OGLESShaderRenderer:

[java]public void onFrame() {

if (checkErrors){

int error = GLES20.glGetError();

if (error != GLES20.GL_NO_ERROR){

throw new RendererException("OpenGL Error " + error + ". Enable error checking for more info.");

}

}

objManager.deleteUnused(this);

// statistics.clearFrame();



if (screenshot) {

screenshot = false;

int size = vpW * vpH;

ByteBuffer buf = ByteBuffer.allocateDirect(size * 4);

buf.order(ByteOrder.nativeOrder());

GLES20.glReadPixels(0, 0, vpW, vpH, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, buf);

int data[] = new int[size];

buf.asIntBuffer().get(data);

buf = null;

bitmap = Bitmap.createBitmap(vpW, vpH, Bitmap.Config.ARGB_8888);

bitmap.setPixels(data, size - vpW, -vpW, 0, 0, vpW, vpH);

data = null;

}

}[/java]