2013-05-18 36 views
5

Trong trường hợp của tôi, tôi không sử dụng RenderSurfaceView. Tôi muốn chụp ảnh màn hình của mình. Nhưng khi tôi lưu ảnh chụp màn hình, nó sẽ hiển thị hình ảnh phản chiếu lộn ngược. Không hiểu những gì im làm sai ở đây.Chụp màn hình trong andengine cung cấp hình ảnh phản chiếu lộn ngược

Đây là mã của tôi

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(); 
               } 
              }); 
           } 
          }); 

! [Đây là ảnh chụp màn hình i được 1

Nó sẽ là một trợ giúp lớn nếu có ai có thể tìm kiếm này ra cho tôi. Cảm ơn.

Trả lời

3

cập nhật GLES2-AnchorCenter

AndEngine/src/org/andengine/tổ chức/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

Cám ơn cụ này. – Siddharth

+1

Trên thực tế có một lỗi, nếu pGrabY khác với 0 nó cho một ArrayOutOFBoundsException. Dòng phải là 'pixel [x + (pGrabHeight - y - 1) * pGrabWidth] = pixelsARGB_8888 [x + y * pGrabWidth];' không có pGrabY trong phần thứ hai của phép gán. – Orgmir