Java 类com.badlogic.gdx.utils.ScreenUtils 实例源码

项目:ProjektGG    文件:ScreenshotUtils.java   
public static void takeScreenshot() {
    byte[] pixels = ScreenUtils.getFrameBufferPixels(0, 0,
            Gdx.graphics.getBackBufferWidth(),
            Gdx.graphics.getBackBufferHeight(), true);

    Pixmap pixmap = new Pixmap(Gdx.graphics.getBackBufferWidth(),
            Gdx.graphics.getBackBufferHeight(), Pixmap.Format.RGBA8888);
    BufferUtils.copy(pixels, 0, pixmap.getPixels(), pixels.length);

    SimpleDateFormat dateFormat = new SimpleDateFormat(
            "yyyy-MM-dd HH-mm-ss");

    PixmapIO.writePNG(
            Gdx.files.external(dateFormat.format(new Date()) + ".png"),
            pixmap);
    pixmap.dispose();
}
项目:Cubes_2    文件:Graphics.java   
public static void takeScreenshot() {
    Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, Gdx.graphics.getBackBufferWidth(),
            Gdx.graphics.getBackBufferHeight());
    FileHandle dir = Compatibility.get().getBaseFolder().child("screenshots");
    dir.mkdirs();
    FileHandle f = dir.child(System.currentTimeMillis() + ".png");
    try {
        PixmapIO.PNG writer = new PixmapIO.PNG((int) (pixmap.getWidth() * pixmap.getHeight() * 1.5f));
        try {
            writer.setFlipY(true);
            writer.write(f, pixmap);
        } finally {
            writer.dispose();
        }
    } catch (IOException ex) {
        throw new CubesException("Error writing PNG: " + f, ex);
    } finally {
        pixmap.dispose();
    }
    Log.info("Took screenshot '" + f.file().getAbsolutePath() + "'");
}
项目:Cubes    文件:Graphics.java   
public static void takeScreenshot() {
  Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight());
  FileHandle dir = Compatibility.get().getBaseFolder().child("screenshots");
  dir.mkdirs();
  FileHandle f = dir.child(System.currentTimeMillis() + ".png");
  try {
    PixmapIO.PNG writer = new PixmapIO.PNG((int) (pixmap.getWidth() * pixmap.getHeight() * 1.5f));
    try {
      writer.setFlipY(true);
      writer.write(f, pixmap);
    } finally {
      writer.dispose();
    }
  } catch (IOException ex) {
    throw new CubesException("Error writing PNG: " + f, ex);
  } finally {
    pixmap.dispose();
  }
  Log.info("Took screenshot '" + f.file().getAbsolutePath() + "'");
}
项目:gdxjam-ugg    文件:ScreenshotFactory.java   
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;
}
项目:Argent    文件:ScreenshotFactory.java   
private static Pixmap getScreenshot(final int x, final int y, final int w, final int h, final boolean yDown)
{

    final Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(x, y, w, h);

    if (yDown)
    {
        // Flip the pixmap upside down
        final ByteBuffer pixels = pixmap.getPixels();
        final int numBytes = w * h * 4;
        final byte[] lines = new byte[numBytes];
        final 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;
}
项目:GDXJam    文件:ScreenshotFactory.java   
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;
}
项目:nvlist    文件:GLScreenRenderer.java   
@Override
public void renderScreenshot(IWritableScreenshot ss, Rect glRect) {
    final ITextureData texData;
    if (ss.isVolatile()) {
        TextureRegion textureRegion = ScreenUtils.getFrameBufferTexture(glRect.x, glRect.y, glRect.w, glRect.h);
        GdxTextureUtil.setDefaultTextureParams(textureRegion.getTexture());
        textureRegion.flip(false, true);
        texData = VolatileTextureData.fromRegion(textureRegion, false);
    } else {
        Pixmap pixels = GdxScreenshotUtil.screenshot(glRect);
        texData = PixelTextureData.fromPremultipliedPixmap(pixels);
    }

    Rect glSize = renderEnv.getGLClip();
    ss.setPixels(texData, Dim.of(glSize.w, glSize.h));
}
项目:ns2-scc-profiler    文件:ScreenshotHelper.java   
public void screenshot(String filename) {
    if (fbo != null) {
        FileHandle local = Gdx.files.local(filename);
        try {
            FileHandle fh;
            do {
                fh = local;
            } while (fh.exists());
            byte[] frameBufferPixels = ScreenUtils.getFrameBufferPixels(0, 0, G.CANVAS_WIDTH, G.CANVAS_HEIGHT, true);
            Pixmap pixmap = new Pixmap(G.CANVAS_WIDTH, G.CANVAS_HEIGHT, Pixmap.Format.RGBA8888);
            pixmap.getPixels().put(frameBufferPixels);
            PixmapIO.writePNG(fh, pixmap);
            pixmap.dispose();

            fbo.end();
            fbo.dispose();

        } catch (Exception e) {
        }
    }
}
项目:ForgE    文件:ScreenshotFactory.java   
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;
}
项目:ForgE    文件:ScreenshotFactory.java   
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;
}
项目:libgdxcn    文件:PngTest.java   
public void render () {
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    batch.begin();
    if (screenshot == null) {
        int width = Gdx.graphics.getWidth(), height = Gdx.graphics.getHeight();
        for (int i = 0; i < 100; i++)
            batch.draw(badlogic, MathUtils.random(width), MathUtils.random(height));
        batch.flush();

        FileHandle file = FileHandle.tempFile("screenshot-");
        System.out.println(file.file().getAbsolutePath());
        Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        try {
            PNG writer = new PNG((int)(pixmap.getWidth() * pixmap.getHeight() * 1.5f));
            // writer.setCompression(Deflater.NO_COMPRESSION);
            writer.write(file, pixmap);
            writer.dispose();
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
        screenshot = new Texture(file);
    }
    batch.draw(screenshot, 0, 0);
    batch.end();
}
项目:snappyfrog    文件:ScreenshotFactory.java   
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;
}
项目:ns2-scc-profiler    文件:ScreenshotHelper.java   
public void screenshot(String filename) {
    if (fbo != null) {
        FileHandle local = Gdx.files.local(filename);
        try {
            FileHandle fh;
            do {
                fh = local;
            } while (fh.exists());
            byte[] frameBufferPixels = ScreenUtils.getFrameBufferPixels(0, 0, G.CANVAS_WIDTH, G.CANVAS_HEIGHT, true);
            Pixmap pixmap = new Pixmap(G.CANVAS_WIDTH, G.CANVAS_HEIGHT, Pixmap.Format.RGBA8888);
            pixmap.getPixels().put(frameBufferPixels);
            PixmapIO.writePNG(fh, pixmap);
            pixmap.dispose();

            fbo.end();
            fbo.dispose();

        } catch (Exception e) {
        }
    }
}
项目:Vloxlands    文件:Vloxlands.java   
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;
}
项目:Stray-core    文件:ScreenshotFactory.java   
public 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;
}
项目:ead    文件:MeshHelper.java   
/**
 * Initializes the mesh with the pixels of the given group.
 * 
 * The result vectors must be in {@link #scaledView} coordinates.
 * 
 * @param toEdit
 * @param resultOrigin
 * @param resultSize
 */
public void show(Group toEdit, Vector2 resultOrigin, Vector2 resultSize) {
    int x = MathUtils.round(resultOrigin.x), y = MathUtils
            .round(resultOrigin.y), width = (int) resultSize.x, height = (int) resultSize.y;
    minX = x;
    minY = y;
    maxX = minX + width;
    maxY = minY + height;

    scaledView.localToStageCoordinates(temp.set(x, y));
    int stageX = MathUtils.round(temp.x), stageY = MathUtils.round(temp.y);

    Batch batch = controller.getPlatform().getBatch();
    batch.setProjectionMatrix(combinedMatrix);
    fbo.begin();
    batch.begin();
    toEdit.draw(batch, 1f);
    batch.end();
    currModifiedPixmap = new PixmapRegion(ScreenUtils.getFrameBufferPixmap(
            stageX, stageY, width, height), stageX, stageY);
    fbo.end();
}
项目:Hexpert    文件:PlayScreen.java   
public Pixmap getMapScreenShot()
{

    float oldCameraZoom = getCamera().zoom;
    float oldCameraX = getCamera().position.x;
    float oldCameraY = getCamera().position.y;

    MapUtils.adjustCamera(getCamera(), grid);

    final FrameBuffer fbo = new FrameBuffer(Pixmap.Format.RGBA8888, WIDTH, HEIGHT, false);

    fbo.begin();
    batch.setProjectionMatrix(getCamera().combined);
    batch.begin();

    for(int i = 0; i < grid.getHexs().length; i++)
    {
        drawHexagon(grid.getHexs()[i], batch);
    }

    batch.end();
    Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, WIDTH, HEIGHT);
    fbo.end();

    //fbo.dispose();

    getCamera().zoom = oldCameraZoom;
    getCamera().position.x = oldCameraX;
    getCamera().position.y = oldCameraY;

    return pixmap;
}
项目:GangsterSquirrel    文件:MainGameClass.java   
/**
 * Takes a screenshot of the current game state and saves it in the assets directory
 */
public void takeScreenshot() {
    byte[] pixels = ScreenUtils.getFrameBufferPixels(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight(), true);
    Pixmap pixmap = new Pixmap(Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight(), Pixmap.Format.RGBA8888);
    BufferUtils.copy(pixels, 0, pixmap.getPixels(), pixels.length);
    PixmapIO.writePNG(Gdx.files.local("screenshots/screenshot.png"), pixmap);
    pixmap.dispose();
}
项目:jrpg-engine    文件:ScreenShotUtil.java   
public static void takeScreenShot(final String filePath) {
    byte[] pixels = ScreenUtils.getFrameBufferPixels(
            0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight(), true
    );

    Pixmap pixmap = new Pixmap(
            Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight(), Pixmap.Format.RGBA8888
    );
    BufferUtils.copy(pixels, 0, pixmap.getPixels(), pixels.length);
    PixmapIO.writePNG(Gdx.files.external(filePath), pixmap);
    pixmap.dispose();
}
项目:libgdx-get-image    文件:Main.java   
private ByteArrayOutputStream getPNG() throws GetPNGException, IOException {
  Gdx.app.log("Main","getPNG enter");

  ByteArrayOutputStream inMemoryStream = new ByteArrayOutputStream(getWidth() * getHeight() * 4);
  PixmapIO.PNG pngWriter = new PixmapIO.PNG((int)(getWidth() * getHeight() * 1.5f));

  Pixmap pixmap = null;

  try {
    Gdx.app.log("Main","getPNG getFrameBufferPixmap");
    pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, getWidth(), getHeight());

    checkForGlError();

    Gdx.app.log("Main","getPNG writing pixmap to inMemoryStream");
    pngWriter.write(inMemoryStream, pixmap);

    checkForGlError();

  }
  catch (GlErrorException e) {
    throw new GetPNGException(e);
  }
  finally {
    if(pixmap != null) pixmap.dispose();
  }
  Gdx.app.log("Main","getPNG exit");

  return inMemoryStream;
}
项目:joe    文件:MainCamera.java   
public void takeScreenshot() {
    byte[] pixels = ScreenUtils.getFrameBufferPixels(0, 0, Gdx.graphics.getBackBufferWidth(),
            Gdx.graphics.getBackBufferHeight(), true);
    Pixmap pixmap = new Pixmap(Gdx.graphics.getBackBufferWidth(),
            Gdx.graphics.getBackBufferHeight(), Pixmap.Format.RGBA8888);
    BufferUtils.copy(pixels, 0, pixmap.getPixels(), pixels.length);
    PixmapIO.writePNG(Gdx.files.external(UUID.randomUUID().toString() + ".png"), pixmap);
    pixmap.dispose();
}
项目:Virtual-Evil    文件:UiInputProcessor.java   
private static void saveScreenshot() {
     try {
         FileHandle fh;
         do {
             fh = new FileHandle("screenshots/screenshot" + screenShotCounter++ + ".png");
         } while (fh.exists());
         Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0,
                 Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

/* flip the resulting image as opengl draws the
 * opposite way of writing to file */
         ByteBuffer pixels = pixmap.getPixels();
         int numBytes = Gdx.graphics.getWidth() * Gdx.graphics.getHeight() * 4;
         byte[] lines = new byte[numBytes];
         int numBytesPerLine = Gdx.graphics.getWidth() * 4;
         for (int i = 0; i < Gdx.graphics.getHeight(); i++) {
             pixels.position((Gdx.graphics.getHeight() - i - 1) * numBytesPerLine);
             pixels.get(lines, i * numBytesPerLine, numBytesPerLine);
         }
         pixels.clear();
         pixels.put(lines);
         pixels.clear();

         PixmapIO.writePNG(fh, pixmap);
         pixmap.dispose();
     } catch (Exception e) {
         e.printStackTrace();
     }
 }
项目:libgdxcn    文件:AlphaTest.java   
@Override
public void render () {
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    batch.begin();
    batch.draw(texture, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    batch.end();

    Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0,  0,  Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    int color = pixmap.getPixel(0, pixmap.getHeight() - 1);
    Gdx.app.log("AlphaTest", Integer.toHexString(color));
    pixmap.dispose();
}
项目:libgdxcn    文件:FramebufferToTextureTest.java   
@Override
public void render () {
    Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    Gdx.gl.glClearColor(clearColor.g, clearColor.g, clearColor.b, clearColor.a);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
    Gdx.gl.glEnable(GL20.GL_DEPTH_TEST);
    Gdx.gl.glEnable(GL20.GL_TEXTURE_2D);

    cam.update();

    modelInstance.transform.rotate(Vector3.Y, 45 * Gdx.graphics.getDeltaTime());
    modelBatch.begin(cam);
    modelBatch.render(modelInstance);
    modelBatch.end();

    if (Gdx.input.justTouched() || fbTexture == null) {
        if (fbTexture != null) fbTexture.getTexture().dispose();
        fbTexture = ScreenUtils.getFrameBufferTexture();
    }

    batch.begin();
    if (fbTexture != null) {
        batch.draw(fbTexture, 0, 0, 100, 100);
    }
    font.draw(batch, "Touch screen to take a snapshot", 10, 40);
    batch.end();
}
项目:bladecoder-adventure-engine    文件:World.java   
public void takeScreenshot(String filename, int w) {

        int h = (int) (w * getSceneCamera().viewportHeight / getSceneCamera().viewportWidth);

        FrameBuffer fbo = new FrameBuffer(Format.RGB565, w, h, false);

        fbo.begin();
        Gdx.gl.glClearColor(0, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        draw();
        Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, w, h);
        fbo.end();

        // 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);

        PixmapIO.writePNG(EngineAssetManager.getInstance().getUserFile(filename), pixmap);

        fbo.dispose();
    }
项目:bladecoder-adventure-engine    文件:SceneList.java   
private TextureRegion createBgIcon(String atlas, String region) {
    TextureAtlas a = new TextureAtlas(
            Gdx.files.absolute(Ctx.project.getAssetPath() + Project.ATLASES_PATH + "/1/" + atlas + ".atlas"));
    AtlasRegion r = a.findRegion(region);

    if (r == null) {
        a.dispose();
        return null;
    }

    GLFrameBuffer.FrameBufferBuilder frameBufferBuilder = new GLFrameBuffer.FrameBufferBuilder(200,
            (int) (r.getRegionHeight() * 200f / r.getRegionWidth()));

    frameBufferBuilder.addColorTextureAttachment(GL30.GL_RGBA8, GL30.GL_RGBA, GL30.GL_UNSIGNED_BYTE);
    FrameBuffer fbo = frameBufferBuilder.build();

    SpriteBatch fboBatch = new SpriteBatch();
    fboBatch.setColor(Color.WHITE);
    OrthographicCamera camera = new OrthographicCamera();
    camera.setToOrtho(false, fbo.getWidth(), fbo.getHeight());
    fboBatch.setProjectionMatrix(camera.combined);

    Gdx.gl.glDisable(GL20.GL_SCISSOR_TEST);
    fbo.begin();
    fboBatch.begin();
    fboBatch.draw(r, 0, 0, fbo.getWidth(), fbo.getHeight());
    fboBatch.end();

    TextureRegion tex = ScreenUtils.getFrameBufferTexture(0, 0, fbo.getWidth(), fbo.getHeight());
    // tex.flip(false, true);

    fbo.end();
    Gdx.gl.glEnable(GL20.GL_SCISSOR_TEST);

    fbo.dispose();
    a.dispose();
    fboBatch.dispose();

    return tex;
}
项目:ead    文件:MeshHelper.java   
private void takePixmap(int x, int y, int width, int height) {
    fbo.begin();
    drawMesh();
    currModifiedPixmap = new PixmapRegion(
            ScreenUtils.getFrameBufferPixmap(x, y, width, height), x, y);
    fbo.end();
}
项目:ead    文件:CreateSceneThumbnail.java   
@Override
public void result(Object... results) {
    int step = (Integer) results[0];
    Gdx.gl.glClearColor(1f, 1f, 1f, 1f);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    batch.begin();
    batch.draw(frameBuffer.getColorBufferTexture(), 0, 0);
    batch.end();

    int width = frameBuffer.getWidth() / STEPS;
    pixmaps[step] = ScreenUtils.getFrameBufferPixmap(step * width, 0,
            width, frameBuffer.getHeight());
}
项目:Klooni1010    文件:ShareChallenge.java   
public boolean saveChallengeImage(final int score, final boolean timeMode) {
    final File saveAt = getShareImageFilePath();
    if (!saveAt.getParentFile().isDirectory())
        if (!saveAt.mkdirs())
            return false;

    final FileHandle output = new FileHandle(saveAt);

    final Texture shareBase = new Texture(Gdx.files.internal("share.png"));
    final int width = shareBase.getWidth();
    final int height = shareBase.getHeight();

    final FrameBuffer frameBuffer = new FrameBuffer(Pixmap.Format.RGB888, width, height, false);
    frameBuffer.begin();

    // Render the base share texture
    final SpriteBatch batch = new SpriteBatch();
    final Matrix4 matrix = new Matrix4();
    matrix.setToOrtho2D(0, 0, width, height);
    batch.setProjectionMatrix(matrix);

    Gdx.gl.glClearColor(Color.GOLD.r, Color.GOLD.g, Color.GOLD.b, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    batch.begin();
    batch.draw(shareBase, 0, 0);

    // Render the achieved score
    final Label.LabelStyle style = new Label.LabelStyle();
    style.font = new BitmapFont(Gdx.files.internal("font/x1.0/geosans-light64.fnt"));
    Label label = new Label("just scored " + score + " on", style);
    label.setColor(Color.BLACK);
    label.setPosition(40, 500);
    label.draw(batch, 1);

    label.setText("try to beat me if you can");
    label.setPosition(40, 40);
    label.draw(batch, 1);

    if (timeMode) {
        Texture timeModeTexture = new Texture("ui/x1.5/stopwatch.png");
        batch.setColor(Color.BLACK);
        batch.draw(timeModeTexture, 200, 340);
    }

    batch.end();

    // Get the framebuffer pixels and write them to a local file
    final byte[] pixels = ScreenUtils.getFrameBufferPixels(0, 0, width, height, true);

    final Pixmap pixmap = new Pixmap(width, height, Pixmap.Format.RGBA8888);

    BufferUtils.copy(pixels, 0, pixmap.getPixels(), pixels.length);
    PixmapIO.writePNG(output, pixmap);

    // Dispose everything
    pixmap.dispose();
    shareBase.dispose();
    batch.dispose();
    frameBuffer.end();

    return true;
}
项目:fabulae    文件:MinimapGenerator.java   
/**
 * Returns an UNMANAGED texture that of the supplied size that
 * contains a map of the supplied game map.
 * 
 * @param map
 * @param gameState
 * @param width
 * @param height
 * @return
 */
public static Texture generate(GameMap map, GameState gameState, int width, int height) {

    boolean isIsometric = map.isIsometric();
    GameMapRenderer renderer = isIsometric ? new IsometricMinimapRenderer(gameState, map) : new OrthogonalMinimapRenderer(gameState, map);

    FrameBuffer fb = new FrameBuffer(Format.RGB565, width, height, false);
    float cameraWidth = map.getWidth();
    float cameraHeight = map.getHeight();
    if (isIsometric) {
        cameraWidth = cameraHeight = (float)(Math.sqrt(cameraWidth*cameraWidth + cameraHeight*cameraHeight) * Math.sqrt(2));
        cameraHeight /= 2;
    }

    float cameraPositionX = cameraWidth / 2;
    float cameraPositionY = isIsometric ? 0 : cameraHeight / 2;

    int tileSizeX = (int) map.getTileSizeX();
    int tileSizeY = (int) map.getTileSizeY();
    if (cameraWidth * tileSizeX < width || cameraHeight * tileSizeY < height) {
        cameraWidth = (float) width / tileSizeX;
        cameraHeight = (float) height / tileSizeY;
    }
       OrthographicCamera camera = new OrthographicCamera(cameraWidth, cameraHeight);
       camera.position.x = cameraPositionX;
       camera.position.y = cameraPositionY;
       camera.update();

    fb.begin();
    Gdx.gl.glClearColor(0f, 0f, 0f, 1f);
    Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT);
    renderer.render(0, camera);
    byte[] bytes = ScreenUtils.getFrameBufferPixels(0, 0, width, height, true);
    fb.end();

    fb.dispose();
    renderer.dispose();

    Pixmap pixmap = new Pixmap(width, height, Format.RGBA8888);
    ByteBuffer pixels = pixmap.getPixels();
    pixels.clear();
    pixels.put(bytes);
    pixels.position(0);

    Texture returnValue = new Texture(pixmap);
    pixmap.dispose();
    return returnValue;

}
项目:nvlist    文件:GdxScreenshotUtil.java   
/**
 * Takes a screenshot of the current OpenGL framebuffer.
 */
public static Pixmap screenshot(Rect glRect) {
    Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(glRect.x, glRect.y, glRect.w, glRect.h);
    PixmapUtil.flipVertical(pixmap);
    return pixmap;
}
项目:gaiasky    文件:GlobalResources.java   
/**
 * Converts a texture to a pixmap by drawing it to a frame buffer and
 * getting the data
 * 
 * @param tex
 *            The texture to convert
 * @return The resulting pixmap
 */
public static Pixmap textureToPixmap(TextureRegion tex) {

    //width and height in pixels
    int width = tex.getRegionWidth();
    int height = tex.getRegionWidth();

    //Create a SpriteBatch to handle the drawing.
    SpriteBatch sb = new SpriteBatch();

    //Set the projection matrix for the SpriteBatch.
    Matrix4 projectionMatrix = new Matrix4();

    //because Pixmap has its origin on the topleft and everything else in LibGDX has the origin left bottom
    //we flip the projection matrix on y and move it -height. So it will end up side up in the .png
    projectionMatrix.setToOrtho2D(0, -height, width, height).scale(1, -1, 1);

    //Set the projection matrix on the SpriteBatch
    sb.setProjectionMatrix(projectionMatrix);

    //Create a frame buffer.
    FrameBuffer fb = new FrameBuffer(Pixmap.Format.RGBA8888, width, height, false);

    //Call begin(). So all next drawing will go to the new FrameBuffer.
    fb.begin();

    //Set up the SpriteBatch for drawing.
    sb.begin();

    //Draw all the tiles.
    sb.draw(tex, 0, 0, width, height);

    //End drawing on the SpriteBatch. This will flush() any sprites remaining to be drawn as well.
    sb.end();

    //Then retrieve the Pixmap from the buffer.
    Pixmap pm = ScreenUtils.getFrameBufferPixmap(0, 0, width, height);

    //Close the FrameBuffer. Rendering will resume to the normal buffer.
    fb.end();

    //Dispose of the resources.
    fb.dispose();
    sb.dispose();

    return pm;
}
项目:crabox    文件:Utils.java   
public static Pixmap takeScreenShoot() {
    return ScreenUtils.getFrameBufferPixmap(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
}
项目:NASAChallengeDebris    文件:MyGDXSattelite.java   
public void getFrame() {
   byte[] bytes = ScreenUtils.getFrameBufferPixels(0, 0,Gdx.graphics.getWidth(), Gdx.graphics.getHeight(),false );

}