<small id='ksfpF'></small><noframes id='ksfpF'>

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

        使用 ScreenUtils 将屏幕截图保存为 libgdx 中的图像

        时间:2023-05-19
          <bdo id='O2nvh'></bdo><ul id='O2nvh'></ul>

          <small id='O2nvh'></small><noframes id='O2nvh'>

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

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

                1. <tfoot id='O2nvh'></tfoot>
                    <tbody id='O2nvh'></tbody>

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

                  问题描述

                  限时送ChatGPT账号..

                  我正在使用 ScreenUtils.getFrameBufferPixels(...) 来截取游戏画面.我想将此方法返回的字节数组保存为文件中的图像.我正在使用 libGDX,我的重点是 android.

                  I am using ScreenUtils.getFrameBufferPixels(...) to take a screenshot of the game screen. I want to save the byte array returned by this method as an image in file. I am using libGDX and my focus in android.

                  推荐答案

                  现在相当容易.Libgdx 提供了一个示例.

                  It is now fairly easy. Libgdx provides an example.

                  我必须添加一条语句才能使其正常工作.图片无法直接保存到 /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;
                      }
                  }
                  

                  这篇关于使用 ScreenUtils 将屏幕截图保存为 libgdx 中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Libgdx 第一人称相机控制 下一篇:libgdx - Group.draw 中的 ShapeRenderer 以错误的颜色呈现

                  相关文章

                  最新文章

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

                    <small id='UJkHZ'></small><noframes id='UJkHZ'>

                      <tfoot id='UJkHZ'></tfoot>

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