0

我以 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);

                }

        };
}
4

1 回答 1

1

您无法截取未渲染的内容!

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

于 2012-04-12T18:55:33.307 回答