2013-05-18 64 views
5

在我的情況下,我沒有使用RenderSurfaceView。我想拍攝我的場景。 但是,當我保存屏幕截圖時,會顯示顛倒的鏡像。不能明白我在這裏做錯了什麼。andengine中的屏幕截圖給出顛倒鏡像

這裏是我的代碼

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

這將是一個很大的幫助,如果任何人都可以尋求這一點對我來說。 謝謝。

回答

3

更新GLES2-AnchorCenter

AndEngine/SRC /組織/ andengine /實體/ 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); 
} 
+0

感謝這個東西。 – Siddharth

+1

實際上有一個錯誤,如果pGrabY不是0,它會給出ArrayOutOFBoundsException。該行應該是'pixels [x +(pGrabHeight - y - 1)* pGrabWidth] = pixelsARGB_8888 [x + y * pGrabWidth];'在分配的第二部分沒有pGrabY。 – Orgmir