andengine 中的屏幕截图给出了倒置的镜像 [英] Screen Capture in andengine gives upside down mirror image

查看:23
本文介绍了andengine 中的屏幕截图给出了倒置的镜像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的情况下,我没有使用 RenderSurfaceView.我想对我的场景进行屏幕截图.但是当我保存屏幕截图时,它显示颠倒的镜像.无法理解我在这里做错了什么.

In my situation i haven't use RenderSurfaceView. I want to take a screen capture of my scene. But when i save the screen shot it shows upside down mirror image. Cant understand what im doing wrong here.

这是我的代码

attachChild(screenCapture);

                    share_clicked = 1;

                    final int viewWidth = (int)camera.getWidth();
                    final int viewHeight = (int)camera.getHeight();

                    Log.d("camera width", "View width :" + viewWidth);
                    Log.d("camera height", "View height :" + viewHeight);


                    File direct = new File(
                            Environment.getExternalStorageDirectory()
                                    + "/Word");

                    if (!direct.exists()) {
                        if (direct.mkdir())
                            ; // directory is created;

                    }

                    screenCapture.capture(
                            viewWidth,
                            viewHeight,
                            direct.getAbsolutePath() + "/word"
                                    + System.currentTimeMillis() + ".png",

                            new IScreenCaptureCallback() {

                                public void onScreenCaptured(
                                        final String pFilePath) {
                                    activity
                                            .runOnUiThread(new Runnable() {

                                                public void run() {
                                                    Toast.makeText(
                                                            activity,
                                                            "Image Successfully saved to 'Word' folder in SD Card.",
                                                            Toast.LENGTH_SHORT)
                                                            .show();
                                                }
                                            });

                                }

                                public void onScreenCaptureFailed(
                                        final String pFilePath,
                                        final Exception pException) {


                                    activity.runOnUiThread(new Runnable() {

                                                public void run() {
                                                    Toast.makeText(
                                                            activity,
                                                            "Failed saving the image! Please check SD card.",
                                                            Toast.LENGTH_SHORT)
                                                            .show();
                                                }
                                            });
                                }
                            });

![这是我得到的屏幕截图1

![this is the screen shot i gets1

如果有人能帮我找到这个,那将是一个很大的帮助.谢谢.

It would be a great help if anyone could sought this out for me. Thanks.

推荐答案

更新 GLES2-AnchorCenter

update GLES2-AnchorCenter

AndEngine/src/org/andengine/entity/util/ScreenGrabber.java

AndEngine/src/org/andengine/entity/util/ScreenGrabber.java

private static Bitmap grab(final int pGrabX, final int pGrabY, final int pGrabWidth, final int pGrabHeight) {
    final int[] pixelsRGBA_8888 = new int[pGrabWidth * pGrabHeight];
    final IntBuffer pixelsRGBA_8888_Buffer = IntBuffer.wrap(pixelsRGBA_8888);

    // TODO Check availability of OpenGL and GLES20.GL_RGBA combinations that require less conversion operations.
    GLES20.glReadPixels(pGrabX, pGrabY, pGrabWidth, pGrabHeight, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, pixelsRGBA_8888_Buffer);

    /* Convert from RGBA_8888 (Which is actually ABGR as the whole buffer seems to be inverted) --> ARGB_8888. */
    final int[] pixelsARGB_8888 = GLHelper.convertRGBA_8888toARGB_8888(pixelsRGBA_8888);

    final int[] pixels = new int[pGrabWidth * pGrabHeight];

    for (int y = 0; y < pGrabHeight; y++) {
        for (int x = 0; x < pGrabWidth; x++) {
            pixels[x + ((pGrabHeight - y - 1) * pGrabWidth)] = pixelsARGB_8888[x + ((pGrabY + y) * pGrabWidth)];
        }
    }

    return Bitmap.createBitmap(pixels, pGrabWidth, pGrabHeight, Config.ARGB_8888);
}

这篇关于andengine 中的屏幕截图给出了倒置的镜像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆