Java 类com.badlogic.gdx.graphics.PixmapIO 实例源码

项目: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    文件:BitmapFontWriter.java   
/** A utility method to write the given array of pixmaps to the given output directory, with the specified file name. If the
 * pages array is of length 1, then the resulting file ref will look like: "fileName.png".
 *
 * If the pages array is greater than length 1, the resulting file refs will be appended with "_N", such as "fileName_0.png",
 * "fileName_1.png", "fileName_2.png" etc.
 *
 * The returned string array can then be passed to the <tt>writeFont</tt> method.
 *
 * Note: None of the pixmaps will be disposed.
 *
 * @param pages the pages of pixmap data to write
 * @param outputDir the output directory
 * @param fileName the file names for the output images
 * @return the array of string references to be used with <tt>writeFont</tt> */
public static String[] writePixmaps (Pixmap[] pages, FileHandle outputDir, String fileName) {
  if (pages == null || pages.length == 0) throw new IllegalArgumentException("no pixmaps supplied to BitmapFontWriter.write");

  String[] pageRefs = new String[pages.length];

  for (int i = 0; i < pages.length; i++) {
    String ref = pages.length == 1 ? (fileName + ".png") : (fileName + "_" + i + ".png");

    // the ref for this image
    pageRefs[i] = ref;

    // write the PNG in that directory
    PixmapIO.writePNG(outputDir.child(ref), pages[i]);
  }
  return pageRefs;
}
项目:enklave    文件:BitmapFontWriter.java   
/** A utility method to write the given array of pixmaps to the given output directory, with the specified file name. If the
 * pages array is of length 1, then the resulting file ref will look like: "fileName.png".
 *
 * If the pages array is greater than length 1, the resulting file refs will be appended with "_N", such as "fileName_0.png",
 * "fileName_1.png", "fileName_2.png" etc.
 *
 * The returned string array can then be passed to the <tt>writeFont</tt> method.
 *
 * Note: None of the pixmaps will be disposed.
 *
 * @param pages the pages of pixmap data to write
 * @param outputDir the output directory
 * @param fileName the file names for the output images
 * @return the array of string references to be used with <tt>writeFont</tt> */
public static String[] writePixmaps (Pixmap[] pages, FileHandle outputDir, String fileName) {
    if (pages==null || pages.length==0)
        throw new IllegalArgumentException("no pixmaps supplied to BitmapFontWriter.write");

    String[] pageRefs = new String[pages.length];

    for (int i=0; i<pages.length; i++) {
        String ref = pages.length==1 ? (fileName+".png") : (fileName+"_"+i+".png");

        //the ref for this image
        pageRefs[i] = ref;

        //write the PNG in that directory
        PixmapIO.writePNG(outputDir.child(ref), pages[i]);
    }
    return pageRefs;
}
项目:Cubes    文件:BitmapFontWriter.java   
/** A utility method to write the given array of pixmaps to the given output directory, with the specified file name. If the
 * pages array is of length 1, then the resulting file ref will look like: "fileName.png".
 *
 * If the pages array is greater than length 1, the resulting file refs will be appended with "_N", such as "fileName_0.png",
 * "fileName_1.png", "fileName_2.png" etc.
 *
 * The returned string array can then be passed to the <tt>writeFont</tt> method.
 *
 * Note: None of the pixmaps will be disposed.
 *
 * @param pages the pages of pixmap data to write
 * @param outputDir the output directory
 * @param fileName the file names for the output images
 * @return the array of string references to be used with <tt>writeFont</tt> */
public static String[] writePixmaps (Pixmap[] pages, FileHandle outputDir, String fileName) {
  if (pages == null || pages.length == 0) throw new IllegalArgumentException("no pixmaps supplied to BitmapFontWriter.write");

  String[] pageRefs = new String[pages.length];

  for (int i = 0; i < pages.length; i++) {
    String ref = pages.length == 1 ? (fileName + ".png") : (fileName + "_" + i + ".png");

    // the ref for this image
    pageRefs[i] = ref;

    // write the PNG in that directory
    PixmapIO.writePNG(outputDir.child(ref), pages[i]);
  }
  return pageRefs;
}
项目:JavityEngine    文件:BitmapFontWriter.java   
/** A utility method to write the given array of pixmaps to the given output directory, with the specified file name. If the
 * pages array is of length 1, then the resulting file ref will look like: "fileName.png".
 * 
 * If the pages array is greater than length 1, the resulting file refs will be appended with "_N", such as "fileName_0.png",
 * "fileName_1.png", "fileName_2.png" etc.
 * 
 * The returned string array can then be passed to the <tt>writeFont</tt> method.
 * 
 * Note: None of the pixmaps will be disposed.
 * 
 * @param pages the pages of pixmap data to write
 * @param outputDir the output directory
 * @param fileName the file names for the output images
 * @return the array of string references to be used with <tt>writeFont</tt> */
public static String[] writePixmaps (Pixmap[] pages, FileHandle outputDir, String fileName) {
    if (pages==null || pages.length==0)
        throw new IllegalArgumentException("no pixmaps supplied to BitmapFontWriter.write");

    String[] pageRefs = new String[pages.length];

    for (int i=0; i<pages.length; i++) {
        String ref = pages.length==1 ? (fileName+".png") : (fileName+"_"+i+".png");

        //the ref for this image
        pageRefs[i] = ref;

        //write the PNG in that directory
        PixmapIO.writePNG(outputDir.child(ref), pages[i]);
    }
    return pageRefs;
}
项目:Argent    文件:ScreenshotFactory.java   
public static void saveScreenshot(final int w, final int h, final String prefix)
{
    try
    {
        FileHandle fh;
        do
        {
            if (Gdx.app.getType() == ApplicationType.Desktop)
            {
                fh = Gdx.files.local("bin/screenshot_" + prefix + "_" + counter++ + ".png");
            }
            else
            {
                fh = Gdx.files.local("screenshot_" + prefix + "_" + counter++ + ".png");
            }
        }
        while (fh.exists());
        final Pixmap pixmap = getScreenshot(0, 0, w, h, true);
        PixmapIO.writePNG(fh, pixmap);
        pixmap.dispose();
        Gdx.app.log("screenshot", "Screenshot saved to " + fh);
    }
    catch (final Exception e)
    {
    }
}
项目:inari-firefly-libGDX    文件:FilteredTextureData.java   
@Override
public void prepare () {
    if (isPrepared) throw new GdxRuntimeException("Already prepared");
    if (pixmap == null) {
        if (file.extension().equals("cim"))
            pixmap = PixmapIO.readCIM(file);
        else
            pixmap = ensurePot(new Pixmap(file));
        width = pixmap.getWidth();
        height = pixmap.getHeight();
        if (format == null) format = pixmap.getFormat();
    }

    applyFilter( pixmap );

    isPrepared = true;
}
项目: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) {
        }
    }
}
项目:ns2-scc-profiler    文件:ScreenshotHelper.java   
public void saveMapTexture(GameState state, Layer layer) {
    Pixmap pixmap = layer.pixmap;
    try {
        PixmapIO.PNG writer = new PixmapIO.PNG((int) (pixmap.getWidth() * pixmap.getHeight() * 1.5f)); // Guess at deflated size.
        try {
            writer.setFlipY(false);
            ByteArrayOutputStream pngStream = new ByteArrayOutputStream();
            writer.write(pngStream, pixmap);
            state.layer = pngStream.toByteArray();
        } finally {
            writer.dispose();
        }
    } catch (IOException ex) {
        throw new RuntimeException("Could not save map as texture.");
    }
}
项目:libgdxcn    文件:BitmapFontWriter.java   
/** A utility method to write the given array of pixmaps to the given output directory, with the specified file name. If the
 * pages array is of length 1, then the resulting file ref will look like: "fileName.png".
 * 
 * If the pages array is greater than length 1, the resulting file refs will be appended with "_N", such as "fileName_0.png",
 * "fileName_1.png", "fileName_2.png" etc.
 * 
 * The returned string array can then be passed to the <tt>writeFont</tt> method.
 * 
 * Note: None of the pixmaps will be disposed.
 * 
 * @param pages the pages of pixmap data to write
 * @param outputDir the output directory
 * @param fileName the file names for the output images
 * @return the array of string references to be used with <tt>writeFont</tt> */
public static String[] writePixmaps (Pixmap[] pages, FileHandle outputDir, String fileName) {
    if (pages == null || pages.length == 0)
        throw new IllegalArgumentException("no pixmaps supplied to BitmapFontWriter.write");

    String[] pageRefs = new String[pages.length];

    for (int i = 0; i < pages.length; i++) {
        String ref = pages.length == 1 ? (fileName + ".png") : (fileName + "_" + i + ".png");

        // the ref for this image
        pageRefs[i] = ref;

        // write the PNG in that directory
        PixmapIO.writePNG(outputDir.child(ref), pages[i]);
    }
    return pageRefs;
}
项目:gdx-smart-font    文件:BitmapFontWriter.java   
/** A utility method to write the given array of pixmaps to the given output directory, with the specified file name. If the
 * pages array is of length 1, then the resulting file ref will look like: "fileName.png".
 * 
 * If the pages array is greater than length 1, the resulting file refs will be appended with "_N", such as "fileName_0.png",
 * "fileName_1.png", "fileName_2.png" etc.
 * 
 * The returned string array can then be passed to the <tt>writeFont</tt> method.
 * 
 * Note: None of the pixmaps will be disposed.
 * 
 * @param pages the pages of pixmap data to write
 * @param outputDir the output directory
 * @param fileName the file names for the output images
 * @return the array of string references to be used with <tt>writeFont</tt> */
public static String[] writePixmaps (Pixmap[] pages, FileHandle outputDir, String fileName) {
    if (pages==null || pages.length==0)
        throw new IllegalArgumentException("no pixmaps supplied to BitmapFontWriter.write");

    String[] pageRefs = new String[pages.length];

    for (int i=0; i<pages.length; i++) {
        String ref = pages.length==1 ? (fileName+".png") : (fileName+"_"+i+".png");

        //the ref for this image
        pageRefs[i] = ref;

        //write the PNG in that directory
        PixmapIO.writePNG(outputDir.child(ref), pages[i]);
    }
    return pageRefs;
}
项目:gametemplate    文件:MarketUtils.java   
private static void saveScreenshot() throws IOException {
    int w = Gdx.graphics.getWidth();
    int h = Gdx.graphics.getHeight();               
    final Pixmap pixmap = new Pixmap(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), Format.RGBA8888);
    ByteBuffer pixels = pixmap.getPixels();
    Gdx.gl.glReadPixels(0, 0, w, h, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, pixels);
    final int numBytes = w * h * 4;
    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);
    System.out.println("Captured.");
    PixmapIO.writePNG(new FileHandle(androidDir+(++photoNumber)+".png"), pixmap);
}
项目:gaiasky    文件:ImageRenderer.java   
public static String writePixmapToImage(String absoluteLocation, String baseFileName, Pixmap pixmap, ImageType type) {
    /** Make sure the directory exists **/
    FileHandle dir = Gdx.files.absolute(absoluteLocation);
    dir.mkdirs();

    /** Save to file **/
    FileHandle fh = getTarget(absoluteLocation, baseFileName, type);
    switch (type) {
    case PNG:
        PixmapIO.writePNG(fh, pixmap);
        break;
    case JPG:
        JPGWriter.write(fh, pixmap);
        break;
    }
    return fh.path();
}
项目:snappyfrog    文件:ScreenshotFactory.java   
public static String saveScreenshot(String destinationFolder, boolean yDown){
    FileHandle fh;
    try{
        do{
            fh = new FileHandle(destinationFolder + "snappyfrog-" + counter++ + ".png");
        }while (fh.exists());
        Pixmap pixmap = getScreenshot(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), yDown);
        PixmapIO.writePNG(fh, pixmap);
        pixmap.dispose();
    }catch (Exception e){
        System.out.println("Error happened while saving screenshot: " + e.getMessage());
        return "";
    }

    return fh.path();
}
项目: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) {
        }
    }
}
项目:ns2-scc-profiler    文件:ScreenshotHelper.java   
public void saveMapTexture(GameState state, Layer layer) {
    Pixmap pixmap = layer.pixmap;
    try {
        PixmapIO.PNG writer = new PixmapIO.PNG((int) (pixmap.getWidth() * pixmap.getHeight() * 1.5f)); // Guess at deflated size.
        try {
            writer.setFlipY(false);
            ByteArrayOutputStream pngStream = new ByteArrayOutputStream();
            writer.write(pngStream, pixmap);
            state.layer = pngStream.toByteArray();
        } finally {
            writer.dispose();
        }
    } catch (IOException ex) {
        throw new RuntimeException("Could not save map as texture.");
    }
}
项目:gdx-proto    文件:BitmapFontWriter.java   
/** A utility method to write the given array of pixmaps to the given output directory, with the specified file name. If the
 * pages array is of length 1, then the resulting file ref will look like: "fileName.png".
 * 
 * If the pages array is greater than length 1, the resulting file refs will be appended with "_N", such as "fileName_0.png",
 * "fileName_1.png", "fileName_2.png" etc.
 * 
 * The returned string array can then be passed to the <tt>writeFont</tt> method.
 * 
 * Note: None of the pixmaps will be disposed.
 * 
 * @param pages the pages of pixmap data to write
 * @param outputDir the output directory
 * @param fileName the file names for the output images
 * @return the array of string references to be used with <tt>writeFont</tt> */
public static String[] writePixmaps (Pixmap[] pages, FileHandle outputDir, String fileName) {
    if (pages==null || pages.length==0)
        throw new IllegalArgumentException("no pixmaps supplied to BitmapFontWriter.write");

    String[] pageRefs = new String[pages.length];

    for (int i=0; i<pages.length; i++) {
        String ref = pages.length==1 ? (fileName+".png") : (fileName+"_"+i+".png");

        //the ref for this image
        pageRefs[i] = ref;

        //write the PNG in that directory
        PixmapIO.writePNG(outputDir.child(ref), pages[i]);
    }
    return pageRefs;
}
项目:crabox    文件:Utils.java   
public static void saveScreen() {
    int count = 0;
    try {
        FileHandle f;
        do {
            f = new FileHandle("screenshoot"+ count++ +".png");
        }while(f.exists());

        Pixmap px = takeScreenShoot();
        PixmapIO.writePNG(f, px);
        px.dispose();

    }catch(Exception e) {
        e.printStackTrace();
    }
}
项目:libgdx-lwp-template    文件:TemplateMain.java   
private void makeScreenshot(){
    int w = Gdx.graphics.getWidth();
    int h = Gdx.graphics.getHeight();

    Gdx.gl.glPixelStorei(GL10.GL_PACK_ALIGNMENT, 1);
    final Pixmap pixmap = new Pixmap(w, h, Format.RGBA8888);
    ByteBuffer pixels = pixmap.getPixels();
    Gdx.gl.glReadPixels(0, 0, w, h, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, pixels);
    final int numBytes = w * h * 4;
    byte[] lines = new byte[numBytes];

    pixels.clear(); 
    pixels.get(lines);

    String stamp = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(Calendar.getInstance().getTime());
    PixmapIO.writePNG(Gdx.files.local("Screenshot-" + stamp + ".png"), pixmap);
    pixmap.dispose();
}
项目:ead    文件:AsyncImageTest.java   
private void createImage() {
    Pixmap pixmap = new Pixmap(200, 200, Format.RGBA8888);
    pixmap.setColor((float) Math.random(), (float) Math.random(),
            (float) Math.random(), 1.0f);
    pixmap.fill();
    PixmapIO.writePNG(
            controller.getApplicationAssets().absolute(
                    file.getAbsolutePath()), pixmap);

    Gdx.app.postRunnable(new Runnable() {
        @Override
        public void run() {
            controller.getEditorGameAssets().unload(file.toString());
            controller.getEditorGameAssets().load(file.toString(),
                    Texture.class);
        }
    });
}
项目:shadow-engine    文件:ScreenshotUtil.java   
public static void frameSave(final FileHandle fh) {
    final int w = (int) Shadow.dispw;
    final int h = (int) Shadow.disph;

    final byte[] data = getScreenData(0, 0, w, h);

    Thread thread = new Thread("Screenshot_"+Shadow.rand.nextInt(1024)) {
        @Override
        public void run() {
            Pixmap pixmap = getPixmap(w, h);
            fillPixmap(pixmap, data);

            fh.parent().mkdirs();

            PixmapIO.writePNG(fh, pixmap);
        }
    };
    thread.start();
}
项目:gdx-toolbox    文件:Screenshot.java   
public static void take(String createInPath) {
    String prefix;
    if (Strings.isNullOrEmpty(createInPath))
        prefix = "screenshot";
    else if (createInPath.endsWith("/"))
        prefix = createInPath + "screenshot";
    else
        prefix = createInPath + "/screenshot";

    try {
        FileHandle file;
        do {
            file = new FileHandle(prefix + counter + ".png");
            counter++;
        } while (file.exists());
        Pixmap pixmap = getFrameBufferPixmap(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
        PixmapIO.writePNG(file, pixmap);
        pixmap.dispose();
        Gdx.app.log("Screenshot", String.format("Saved screenshot to %s", file.file().getAbsolutePath()));
    } catch (Exception e) {
    }
}
项目:ingress-indonesia-dev    文件:FileTextureData.java   
public void prepare()
{
  if (this.isPrepared)
    throw new GdxRuntimeException("Already prepared");
  if (this.pixmap == null)
    if (!this.file.extension().equals("cim"))
      break label96;
  label96: for (this.pixmap = PixmapIO.readCIM(this.file); ; this.pixmap = ensurePot(new Pixmap(this.file)))
  {
    this.width = this.pixmap.getWidth();
    this.height = this.pixmap.getHeight();
    if (this.format == null)
      this.format = this.pixmap.getFormat();
    this.isPrepared = true;
    return;
  }
}
项目:Cubes_2    文件:AOTextureGenerator.java   
protected static void generate(FileHandle file, float strength) {
    Pixmap blocks = new Pixmap(INDIVIDUAL_SIZE * 3, INDIVIDUAL_SIZE * 3, AOTextureGenerator.FORMAT);
    Pixmap gaussian = new Pixmap(INDIVIDUAL_SIZE, INDIVIDUAL_SIZE, AOTextureGenerator.FORMAT);

    Pixmap output = new Pixmap(TEXTURE_SIZE, TEXTURE_SIZE, AOTextureGenerator.FORMAT);

    double[][] gwm = AOTextureGenerator.gaussianWeightMatrix(SIGMA);
    int gaussianRadius = (gwm.length - 1) / 2;

    Color blockColor = new Color(strength, strength, strength, 1f);

    for (int i = 0; i < TOTAL; i++) {
        String n = name(i);
        System.out.print(n + " ");

        AOTextureGenerator.clearPixmap(blocks);
        AOTextureGenerator.clearPixmap(gaussian);

        AOTextureGenerator.setupPixmap(blocks, i, blockColor);

        AOTextureGenerator.gaussianPixmap(blocks, gaussian, gwm, gaussianRadius);

        // PixmapIO.writePNG(folder.child(n + "_blocks_" + sigma + ".png"),
        // blocks);
        // PixmapIO.writePNG(folder.child(n + "_gaussian_" + sigma +
        // ".png"), gaussian);

        output.drawPixmap(gaussian, (i % SQRT_TOTAL) * INDIVIDUAL_SIZE, (i / SQRT_TOTAL) * INDIVIDUAL_SIZE, 0, 0,
                INDIVIDUAL_SIZE, INDIVIDUAL_SIZE);

        if (i % SQRT_TOTAL == SQRT_TOTAL - 1)
            System.out.println();
    }

    PixmapIO.writePNG(file, output);
    output.dispose();
    blocks.dispose();
    gaussian.dispose();
}
项目:Cubes_2    文件:Assets.java   
private static PackedTextureSheet getPackedTextureSheet(AssetType... assetType) {
    if (Adapter.isDedicatedServer())
        return null;
    TexturePacker texturePacker = new TexturePacker(2048, 2048, 1, true);
    Pixmap pixmap;
    getPacketTextureSheetFor(assetType, texturePacker, pixmap);

    FileHandle fileHandle = assetsFolder.child("packed");
    fileHandle.mkdirs();
    Compatibility.get().nomedia(fileHandle);
    fileHandle = fileHandle.child(assetType[0].name() + ".cim");

    try {
        PixmapIO.writeCIM(fileHandle, texturePacker.getPixmap());
    } catch (GdxRuntimeException e) {
        Log.error("Failed to write packed image", e);
    }

    Texture texture = new Texture(fileHandle);
    texture.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest);
    PackedTextureSheet packedTextureSheet = new PackedTextureSheet(
            new Material(TextureAttribute.createDiffuse(texture)));
    packedTextureSheet.getMaterial().set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA));

    Map<Asset, TexturePacker.PackRectangle> rectangles = texturePacker.getRectangles();
    int num = 0;
    for (Map.Entry<Asset, TexturePacker.PackRectangle> entry : rectangles.entrySet()) {
        num++;
        TextureRegion textureRegion = new TextureRegion(texture, entry.getValue().x, entry.getValue().y,
                entry.getValue().width, entry.getValue().height);
        entry.getKey().setPackedTextureRegion(textureRegion, packedTextureSheet);
        packedTextureSheet.getPackedTextures().put(entry.getKey().toString(), textureRegion);
    }

    for (AssetType type : assetType) {
        type.setPackedTextureSheet(packedTextureSheet);
    }
    return packedTextureSheet;
}
项目:Cubes    文件:AOTextureGenerator.java   
protected static void generate(FileHandle file, float strength) {
  Pixmap blocks = new Pixmap(INDIVIDUAL_SIZE * 3, INDIVIDUAL_SIZE * 3, AOTextureGenerator.FORMAT);
  Pixmap gaussian = new Pixmap(INDIVIDUAL_SIZE, INDIVIDUAL_SIZE, AOTextureGenerator.FORMAT);

  Pixmap output = new Pixmap(TEXTURE_SIZE, TEXTURE_SIZE, AOTextureGenerator.FORMAT);

  double[][] gwm = AOTextureGenerator.gaussianWeightMatrix(SIGMA);
  int gaussianRadius = (gwm.length - 1) / 2;

  Color blockColor = new Color(strength, strength, strength, 1f);

  for (int i = 0; i < TOTAL; i++) {
    String n = name(i);
    System.out.print(n + " ");

    AOTextureGenerator.clearPixmap(blocks);
    AOTextureGenerator.clearPixmap(gaussian);

    AOTextureGenerator.setupPixmap(blocks, i, blockColor);

    AOTextureGenerator.gaussianPixmap(blocks, gaussian, gwm, gaussianRadius);

    //PixmapIO.writePNG(folder.child(n + "_blocks_" + sigma + ".png"), blocks);
    //PixmapIO.writePNG(folder.child(n + "_gaussian_" + sigma + ".png"), gaussian);

    output.drawPixmap(gaussian, (i % SQRT_TOTAL) * INDIVIDUAL_SIZE, (i / SQRT_TOTAL) * INDIVIDUAL_SIZE, 0, 0, INDIVIDUAL_SIZE, INDIVIDUAL_SIZE);

    if (i % SQRT_TOTAL == SQRT_TOTAL - 1) System.out.println();
  }

  PixmapIO.writePNG(file, output);
  output.dispose();
  blocks.dispose();
  gaussian.dispose();
}
项目: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();
}
项目:gdxjam-ugg    文件:ScreenshotFactory.java   
public static void saveScreenshot () {
String path = directory + "screenshot" + counter++ + ".png";

while(Gdx.files.local(path).exists()){
    counter++;
    path = directory + "screenshot" + counter++ + ".png";
}

    Pixmap pixmap = getScreenshot(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
    PixmapIO.writePNG(Gdx.files.local(path), 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();
}
项目:exterminate    文件:Island.java   
public void export() {
    float world[][] = this.world;

    Pixmap pixmap = new Pixmap(world.length, world.length, Format.RGBA8888);
    float maxh = 0;

    for (int i = 0; i < world.length; i++) {
        for (int j = 0; j < world.length; j++) {
            maxh = Math.max(maxh, world[i][j]);
        }
    }

    for (int i = 0; i < world.length; i++) {
        for (int j = 0; j < world.length; j++) {
            pixmap.setColor(world[i][j] / maxh, world[i][j] / maxh,
                    world[i][j] / maxh, 1);
            if (world[i][j] < IslandManager.hauteurEau) {
                pixmap.setColor(world[i][j] / maxh, world[i][j] / maxh,
                        0.8f, 1);

            }
            pixmap.drawPixel(i, j);
        }
    }
    FileHandle f = new FileHandle("map.png");
    PixmapIO.writePNG(f, pixmap);
    System.out.println("map exported. " + f.path());
}
项目:exterminate    文件:IslandManager.java   
public void export() {
    float world[][] = islands[1][1].world;

Pixmap pixmap = new Pixmap(world.length, world.length, Format.RGBA8888);
    float maxh = 0;

        for(int i=0;i<world.length;i++) {
        for(int j=0;j<world.length;j++) {
            maxh = Math.max(maxh, world[i][j]);
        }           
    }


    for(int i=0;i<world.length;i++) {
        for(int j=0;j<world.length;j++) {
            pixmap.setColor(world[i][j]/maxh, world[i][j]/maxh, world[i][j]/maxh, 1);
            if(world[i][j]<hauteurEau) {
                pixmap.setColor(world[i][j]/maxh, world[i][j]/maxh, 0.8f, 1);

            }
            pixmap.drawPixel(i, j);
        }           
    }
    FileHandle f = new FileHandle("map.png");
    PixmapIO.writePNG(f, pixmap);
    System.out.println("map exported. "+f.path());
  }
项目:space-travels-3    文件:JoystickLoader.java   
private Pixmap createAndSaveJoystick(
    FileHandle fileHandle,
    JoystickParameters joystickParameters)
{
    Pixmap pixmap =
        new Pixmap(
            (int) joystickParameters.size,
            (int) joystickParameters.size,
            Pixmap.Format.RGBA8888);
    pixmap.setColor(joystickParameters.color);

    int numOuterArcs = 8;
    float halfSmallestDimension = joystickParameters.size / 2f;

    PixmapUtils.dashedCircle(
        pixmap,
        halfSmallestDimension,
        halfSmallestDimension,
        halfSmallestDimension,
        numOuterArcs,
        15,
        360 / numOuterArcs / 2,
        100,
        joystickParameters.strokeSize);
    PixmapUtils.dashedCircle(
        pixmap,
        halfSmallestDimension,
        halfSmallestDimension,
        halfSmallestDimension * joystickParameters.deadZone,
        4,
        30,
        0,
        100,
        joystickParameters.strokeSize);

    PixmapIO.writePNG(fileHandle, pixmap);

    return pixmap;
}
项目:space-travels-3    文件:CollisionCache.java   
private void saveBitMap()
{
    Pixmap pixmap = new Pixmap(this.arrayWidth, this.arrayHeight, Pixmap.Format.RGBA8888);

    for (int x = 0; x < this.arrayWidth; x++)
    {
        for (int y = 0; y < this.arrayHeight; y++)
        {
            if (this.collisions[x][y] != null)
            {
                switch (this.collisions[x][y].size())
                {
                    case 0:
                        pixmap.setColor(Color.CLEAR);
                        break;
                    case 1:
                        pixmap.setColor(Color.RED);
                        break;
                    case 2:
                        pixmap.setColor(Color.GREEN);
                        break;
                    case 3:
                        pixmap.setColor(Color.BLUE);
                        break;
                    default:
                        pixmap.setColor(Color.WHITE);
                        break;
                }
                pixmap.drawPixel(x, y);
            }
        }
    }

    PixmapIO.writePNG(FileUtils.getFileHandle("collisionBitmap.png"), pixmap);
}
项目:GDXJam    文件:ScreenshotFactory.java   
public static void saveScreenshot () {
String path = directory + "screenshot" + counter++ + ".png";

while(Gdx.files.local(path).exists()){
    counter++;
    path = directory + "screenshot" + counter++ + ".png";
}

    Pixmap pixmap = getScreenshot(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
    PixmapIO.writePNG(Gdx.files.local(path), pixmap);
    pixmap.dispose();
}
项目:nvlist    文件:PngUtil.java   
/**
 * @see Pixmap#Pixmap(byte[], int, int)
 * @throws IOException If an internal error occurs in the PNG encoder.
 */
public static byte[] encodePng(Pixmap pixmap) throws IOException {
    PixmapIO.PNG encoder = new PixmapIO.PNG();
    encoder.setFlipY(false);

    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    try {
        encoder.write(bout, pixmap);
    } finally {
        bout.close();
        encoder.dispose();
    }

    return bout.toByteArray();
}
项目:nvlist    文件:RenderIntegrationTest.java   
/**
 * Checks the render result by comparing a screenshot of a sub-rect of the current screen to an image file
 * containing the expected result.
 *
 * @param glRect Clip rectangle in OpenGL viewport coordinates (OpenGL uses a flipped y-axis, so y=0 is the bottom
 *        pixel).
 */
public void checkRenderResult(String testName, Rect glRect) {
    Pixmap actual = ScreenshotHelper.screenshot(glRect.x, glRect.y, glRect.w, glRect.h);

    String outputPath = "src/test/resources/render/" + testName + ".png";
    FileHandle fileHandle = Gdx.files.local(outputPath);
    if (generate) {
        PixmapIO.writePNG(fileHandle, actual);
    } else {
        Pixmap expected = new Pixmap(fileHandle);
        pixmapEquals.assertEquals(expected, actual);
    }
}
项目:nvlist    文件:TestImageUtil.java   
/**
 * Writes a pixmap to PNG.
 * @throws IOException If an I/O error occurs while writing to the output stream.
 */
public static void writePng(Pixmap pixmap, OutputStream out) throws IOException {
    PNG encoder = new PixmapIO.PNG();
    try {
        encoder.write(out, pixmap);
    } finally {
        encoder.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();
     }
 }