android andengine场景截图

时间:2012-04-12 14:18:42

标签: android screenshot andengine high-resolution

我使用分辨率1000x1000初始化引擎并希望将整个场景保存在文件中。 如果我使用ScreenCapture类截图,图片的最大分辨率是800x480(因为我的设备(htc欲望)是800x480,并且不可能有更多像素来自屏幕)。但场景更大,也许有办法迭代场景中的所有像素并保存1000x1000图片?

我尝试了以下代码来保存RenderTexture中的图片:

@Override
public Engine onCreateEngine(EngineOptions pEngineOptions)
{
        return new Engine(pEngineOptions) {

            private boolean mRenderTextureInitialized;

            int r[];

            private  RenderTexture mRenderTextures;

            @Override
            public void onDrawFrame(final GLState pGLState) throws InterruptedException {
                final boolean firstFrame = !this.mRenderTextureInitialized;

                if(firstFrame) {
                    this.initRenderTextures(pGLState);
                    this.mRenderTextureInitialized = true;
                }
                this.mRenderTextures.begin(pGLState);

                super.onDrawFrame(pGLState);

                this.mRenderTextures.end(pGLState);

                if (needToSave)
                {
                    needToSave = false;
                    final String location = SAVED_PATH + "/Screen_" + System.currentTimeMillis() + ".png";
                    FSHelper.saveBitmapToFile(mRenderTextures.getBitmap(pGLState), location);
                }


            }

            private void initRenderTextures(final GLState pGLState) {
                final int surfaceWidth = this.mCamera.getSurfaceWidth();
                final int surfaceHeight = this.mCamera.getSurfaceHeight();


                    this.mRenderTextures = new RenderTexture(EnchantActivity.this.getTextureManager(), surfaceWidth, surfaceHeight);
                    this.mRenderTextures.init(pGLState);

                }

        };
}

1 个答案:

答案 0 :(得分:1)

您无法截取未呈现的内容!

但是当使用GLES2分支时,您可以将场景渲染为RenderTexture,它可以是任意大小的。此示例应该有所帮助:https://github.com/nicolasgramlich/AndEngineExamples/blob/GLES2/src/org/andengine/examples/MotionStreakExample.java