Screen Capture in andengine gives upside down mirror image

家住魔仙堡 提交于 2019-12-04 07:36:04

update GLES2-AnchorCenter

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);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!