• <i id='jQA5u'><tr id='jQA5u'><dt id='jQA5u'><q id='jQA5u'><span id='jQA5u'><b id='jQA5u'><form id='jQA5u'><ins id='jQA5u'></ins><ul id='jQA5u'></ul><sub id='jQA5u'></sub></form><legend id='jQA5u'></legend><bdo id='jQA5u'><pre id='jQA5u'><center id='jQA5u'></center></pre></bdo></b><th id='jQA5u'></th></span></q></dt></tr></i><div id='jQA5u'><tfoot id='jQA5u'></tfoot><dl id='jQA5u'><fieldset id='jQA5u'></fieldset></dl></div>
      <bdo id='jQA5u'></bdo><ul id='jQA5u'></ul>

        <tfoot id='jQA5u'></tfoot>

        <legend id='jQA5u'><style id='jQA5u'><dir id='jQA5u'><q id='jQA5u'></q></dir></style></legend>

      1. <small id='jQA5u'></small><noframes id='jQA5u'>

      2. 在 libgdx 中截屏

        时间:2023-07-27

          <legend id='3BnUx'><style id='3BnUx'><dir id='3BnUx'><q id='3BnUx'></q></dir></style></legend>
            <bdo id='3BnUx'></bdo><ul id='3BnUx'></ul>
            <i id='3BnUx'><tr id='3BnUx'><dt id='3BnUx'><q id='3BnUx'><span id='3BnUx'><b id='3BnUx'><form id='3BnUx'><ins id='3BnUx'></ins><ul id='3BnUx'></ul><sub id='3BnUx'></sub></form><legend id='3BnUx'></legend><bdo id='3BnUx'><pre id='3BnUx'><center id='3BnUx'></center></pre></bdo></b><th id='3BnUx'></th></span></q></dt></tr></i><div id='3BnUx'><tfoot id='3BnUx'></tfoot><dl id='3BnUx'><fieldset id='3BnUx'></fieldset></dl></div>
              <tbody id='3BnUx'></tbody>
            <tfoot id='3BnUx'></tfoot>

                <small id='3BnUx'></small><noframes id='3BnUx'>

                  本文介绍了在 libgdx 中截屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一个应用程序,我想在其中截取游戏屏幕的屏幕截图并将其保存为图像并上传到 Facebook.我正在使用 Libgdx,我的重点是 android.

                  I have an application in which i want to take the screenshot of the game screen and save it as an image and upload to Facebook. I am using Libgdx and my focus is android.

                  谁能帮助我如何以编程方式截取游戏屏幕并将其保存为图像??

                  Can anyone help me that how to take screenshot of the game screen programmatically and save it as an image ??

                  推荐答案

                  现在相当容易.Libgdx 提供了一个示例,可以在这里找到.

                  It is now fairly easy. Libgdx provides an example, which can be found here.

                  我必须添加一条语句才能使其正常工作.图片无法直接保存到 /screenshot1.png.只需添加 Gdx.files.getLocalStoragePath().

                  I had to add one statement to get it working. The image could not be saved directly to /screenshot1.png. Simply prepend Gdx.files.getLocalStoragePath().

                  源代码:

                  public class ScreenshotFactory {
                  
                      private static int counter = 1;
                      public static void saveScreenshot(){
                          try{
                              FileHandle fh;
                              do{
                                  fh = new FileHandle(Gdx.files.getLocalStoragePath() + "screenshot" + counter++ + ".png");
                              }while (fh.exists());
                              Pixmap pixmap = getScreenshot(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);
                              PixmapIO.writePNG(fh, pixmap);
                              pixmap.dispose();
                          }catch (Exception e){           
                          }
                      }
                  
                      private static Pixmap getScreenshot(int x, int y, int w, int h, boolean yDown){
                          final Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(x, y, w, h);
                  
                          if (yDown) {
                              // Flip the pixmap upside down
                              ByteBuffer pixels = pixmap.getPixels();
                              int numBytes = w * h * 4;
                              byte[] lines = new byte[numBytes];
                              int numBytesPerLine = w * 4;
                              for (int i = 0; i < h; i++) {
                                  pixels.position((h - i - 1) * numBytesPerLine);
                                  pixels.get(lines, i * numBytesPerLine, numBytesPerLine);
                              }
                              pixels.clear();
                              pixels.put(lines);
                          }
                  
                          return pixmap;
                      }
                  }
                  

                  这篇关于在 libgdx 中截屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:无法为 libgdx 加载共享库 box2d 下一篇:libgdx 在 Mac 上抛出异常,无法加载共享库 libgdx

                  相关文章

                  最新文章

                • <small id='8mStT'></small><noframes id='8mStT'>

                        <bdo id='8mStT'></bdo><ul id='8mStT'></ul>
                      <tfoot id='8mStT'></tfoot>

                    1. <legend id='8mStT'><style id='8mStT'><dir id='8mStT'><q id='8mStT'></q></dir></style></legend>
                    2. <i id='8mStT'><tr id='8mStT'><dt id='8mStT'><q id='8mStT'><span id='8mStT'><b id='8mStT'><form id='8mStT'><ins id='8mStT'></ins><ul id='8mStT'></ul><sub id='8mStT'></sub></form><legend id='8mStT'></legend><bdo id='8mStT'><pre id='8mStT'><center id='8mStT'></center></pre></bdo></b><th id='8mStT'></th></span></q></dt></tr></i><div id='8mStT'><tfoot id='8mStT'></tfoot><dl id='8mStT'><fieldset id='8mStT'></fieldset></dl></div>