Example usage for com.badlogic.gdx.graphics Pixmap drawPixmap

List of usage examples for com.badlogic.gdx.graphics Pixmap drawPixmap

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics Pixmap drawPixmap.

Prototype

public void drawPixmap(Pixmap pixmap, int x, int y, int srcx, int srcy, int srcWidth, int srcHeight) 

Source Link

Document

Draws an area form another Pixmap to this Pixmap.

Usage

From source file:com.o2d.pkayjava.editor.utils.poly.TextureUtils.java

License:Apache License

public static TextureRegion getPOTTexture(String path) {
    if (path == null)
        return null;

    FileHandle file = Gdx.files.absolute(path);
    if (!file.exists())
        return null;

    Pixmap pixmap = new Pixmap(file);
    int origW = pixmap.getWidth();
    int origH = pixmap.getHeight();
    int w = getNearestPOT(origW);
    int h = getNearestPOT(origH);
    int len = Math.max(w, h);

    Pixmap potPixmap = new Pixmap(len, len, pixmap.getFormat());
    potPixmap.drawPixmap(pixmap, 0, 0, 0, 0, origW, origH);
    pixmap.dispose();//from w w w .  j a v a2s  .  c o  m

    Texture texture = new Texture(potPixmap);
    texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);

    return new TextureRegion(texture, 0, 0, origW, origH);
}

From source file:com.o2d.pkayjava.editor.utils.poly.TextureUtils.java

License:Apache License

public static Pixmap getPOTPixmap(String path) {
    if (path == null)
        return null;

    FileHandle file = Gdx.files.absolute(path);
    if (!file.exists())
        return null;

    Pixmap pixmap = new Pixmap(file);
    int origW = pixmap.getWidth();
    int origH = pixmap.getHeight();
    int w = getNearestPOT(origW);
    int h = getNearestPOT(origH);
    int len = Math.max(w, h);

    Pixmap potPixmap = new Pixmap(len, len, pixmap.getFormat());
    potPixmap.drawPixmap(pixmap, 0, 0, 0, 0, origW, origH);
    pixmap.dispose();//from  w  ww .j a  v  a  2  s.c  o m

    return potPixmap;
}

From source file:com.o2d.pkayjava.editor.utils.poly.TextureUtils.java

License:Apache License

public static Pixmap getPOTPixmap(Texture texture) {
    if (texture == null)
        return null;
    texture.getTextureData().prepare();//from w ww.  j  av  a 2  s  . c o m
    Pixmap pixmap = texture.getTextureData().consumePixmap();
    int origW = pixmap.getWidth();
    int origH = pixmap.getHeight();
    int w = getNearestPOT(origW);
    int h = getNearestPOT(origH);
    int len = Math.max(w, h);

    Pixmap potPixmap = new Pixmap(len, len, pixmap.getFormat());
    potPixmap.drawPixmap(pixmap, 0, 0, 0, 0, origW, origH);
    pixmap.dispose();

    return potPixmap;
}

From source file:com.o2d.pkayjava.editor.utils.poly.TextureUtils.java

License:Apache License

public static TextureRegion getPOTTexture(Texture texture) {
    if (texture == null)
        return null;

    texture.getTextureData().prepare();/*  w w w. j a  va2 s.  c om*/
    Pixmap pixmap = texture.getTextureData().consumePixmap();
    int origW = pixmap.getWidth();
    int origH = pixmap.getHeight();
    int w = getNearestPOT(origW);
    int h = getNearestPOT(origH);
    int len = Math.max(w, h);

    Pixmap potPixmap = new Pixmap(len, len, pixmap.getFormat());
    potPixmap.drawPixmap(pixmap, 0, 0, 0, 0, origW, origH);
    pixmap.dispose();

    Texture otherTexture = new Texture(potPixmap);
    otherTexture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);

    return new TextureRegion(otherTexture, 0, 0, origW, origH);
}

From source file:com.sertaogames.cactus2d.misc.MyTileAtlas.java

License:Apache License

private void loadTextures() {
    for (TileSet set : map.tileSets) {
        Pixmap pixmap;// = new Pixmap(inputDir.child(set.imageName));
        pixmap = Cactus2DApplication.loadAsset(dir + "/" + set.imageName, Pixmap.class);

        int originalWidth = pixmap.getWidth();
        int originalHeight = pixmap.getHeight();

        if (!MathUtils.isPowerOfTwo(originalWidth) || !MathUtils.isPowerOfTwo(originalHeight)) {
            final int width = MathUtils.nextPowerOfTwo(originalWidth);
            final int height = MathUtils.nextPowerOfTwo(originalHeight);

            Pixmap potPixmap = new Pixmap(width, height, pixmap.getFormat());
            potPixmap.drawPixmap(pixmap, 0, 0, 0, 0, width, height);
            pixmap.dispose();/*w  w w .ja va  2s . c om*/
            pixmap = potPixmap;
        }
        Texture texture = new Texture(pixmap);
        pixmap.dispose();
        textures.add(texture);

        int idx = 0;
        TextureRegion[][] regions = split(texture, originalWidth, originalHeight, map.tileWidth, map.tileHeight,
                set.spacing, set.margin);
        for (int y = 0; y < regions[0].length; y++) {
            for (int x = 0; x < regions.length; x++) {
                regionsMap.put(idx++ + set.firstgid, regions[x][y]);
            }
        }
    }
}

From source file:com.weimingtom.iteye.simplerpg.tiled.SimpleTileAtlas.java

License:Apache License

/** Creates a TileAtlas for use with {@link TileMapRenderer}.
 * @param map The tiled map//  w w w  .j av  a 2s  .  c o m
 * @param inputDir The directory containing all needed textures in the map */
public SimpleTileAtlas(TiledMap map, FileHandle inputDir) {
    for (TileSet set : map.tileSets) {
        Pixmap pixmap = new Pixmap(inputDir.child(set.imageName));

        int originalWidth = pixmap.getWidth();
        int originalHeight = pixmap.getHeight();

        if (!MathUtils.isPowerOfTwo(originalWidth) || !MathUtils.isPowerOfTwo(originalHeight)) {
            final int width = MathUtils.nextPowerOfTwo(originalWidth);
            final int height = MathUtils.nextPowerOfTwo(originalHeight);

            Pixmap potPixmap = new Pixmap(width, height, pixmap.getFormat());
            potPixmap.drawPixmap(pixmap, 0, 0, 0, 0, width, height);
            pixmap.dispose();
            pixmap = potPixmap;
        }
        Texture texture = new Texture(pixmap);
        pixmap.dispose();
        textures.add(texture);

        int idx = 0;
        TextureRegion[][] regions = split(texture, originalWidth, originalHeight, map.tileWidth, map.tileHeight,
                set.spacing, set.margin);
        for (int y = 0; y < regions[0].length; y++) {
            for (int x = 0; x < regions.length; x++) {
                regionsMap.put(idx++ + set.firstgid, regions[x][y]);
            }
        }
    }
}

From source file:es.eucm.ead.editor.view.builders.scene.draw.MeshHelper.java

License:Open Source License

/**
 * Saves the minimum amount of pixels that encapsulates the drawn image.
 * /*from www  . j  a  v  a2s. c  o m*/
 * @return
 */
Region save(FileHandle file) {
    Pixmap modifPixmap = this.currModifiedPixmap.pixmap;
    PNG writer = null;
    Pixmap savedPixmap = null;
    try {
        savedPixmap = new Pixmap(savedRegion.w, savedRegion.h, modifPixmap.getFormat());

        savedPixmap.drawPixmap(modifPixmap, 0, 0, savedRegion.x, savedRegion.y, savedRegion.w, savedRegion.h);

        savedRegion.x += currModifiedPixmap.x;
        savedRegion.y += currModifiedPixmap.y;
        // Guess at deflated size.
        writer = new PNG((int) (savedPixmap.getWidth() * savedPixmap.getHeight() * 1.5f));
        writer.setFlipY(true);
        writer.write(file, savedPixmap);
    } catch (IOException ex) {
        throw new GdxRuntimeException("Error writing PNG: " + file, ex);
    } finally {
        if (writer != null) {
            writer.dispose();
            writer = null;
        }
        if (savedPixmap != null) {
            savedPixmap.dispose();
            savedPixmap = null;
        }
    }

    return savedRegion;
}

From source file:seventh.client.gfx.TextureUtil.java

License:Open Source License

/**
 * Splits the image //from www  .  java 2s.c  o  m
 * @param image
 * @param width
 * @param height
 * @param row
 * @param col
 * @return
 */
public static Pixmap[] splitPixmap(Pixmap image, int width, int height, int row, int col) {
    int total = col * row; // total returned images
    int frame = 0; // frame counter

    int w = width / col;
    int h = height / row;

    Pixmap[] images = new Pixmap[total];

    for (int j = 0; j < row; j++) {
        for (int i = 0; i < col; i++) {
            Pixmap region = new Pixmap(w, h, image.getFormat());
            region.drawPixmap(image, 0, 0, i * w, j * h, w, h);

            images[frame++] = region;
        }
    }

    return images;
}