Java Code Examples for com.badlogic.gdx.graphics.Pixmap#drawPixmap()

The following examples show how to use com.badlogic.gdx.graphics.Pixmap#drawPixmap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FacedMultiCubemapData.java    From gdx-gltf with Apache License 2.0 6 votes vote down vote up
@Override
public void consumeCubemapData () {
	for(int level = 0 ; level<levels ; level++){
		for (int i = 0; i < 6; i++) {
			int index = level * 6 + i;
			if (data[index].getType() == TextureData.TextureDataType.Custom) {
				data[index].consumeCustomData(GL20.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i);
			} else {
				Pixmap pixmap = data[index].consumePixmap();
				boolean disposePixmap = data[index].disposePixmap();
				if (data[index].getFormat() != pixmap.getFormat()) {
					Pixmap tmp = new Pixmap(pixmap.getWidth(), pixmap.getHeight(), data[index].getFormat());
					tmp.setBlending(Blending.None);
					tmp.drawPixmap(pixmap, 0, 0, 0, 0, pixmap.getWidth(), pixmap.getHeight());
					if (data[index].disposePixmap()) pixmap.dispose();
					pixmap = tmp;
					disposePixmap = true;
				}
				Gdx.gl.glPixelStorei(GL20.GL_UNPACK_ALIGNMENT, 1);
				Gdx.gl.glTexImage2D(GL20.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, level, pixmap.getGLInternalFormat(), pixmap.getWidth(),
					pixmap.getHeight(), 0, pixmap.getGLFormat(), pixmap.getGLType(), pixmap.getPixels());
				if (disposePixmap) pixmap.dispose();
			}
		}
	}
}
 
Example 2
Source File: TextureUtil.java    From seventh with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Splits the image 
 * @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;
}
 
Example 3
Source File: ImageHelper.java    From gdx-fireapp with Apache License 2.0 5 votes vote down vote up
/**
 * Transforms byte[] to Texture Region.
 * <p>
 * If you are going to call this method inside firebase callback remember to wrap it<p>
 * into {@code Gdx.app.postRunnable(Runnable)}.
 * The texture will be changed so that it has sides with length of power of 2.
 *
 * @param bytes Byte array with image description
 * @return Texture region representation of given byte array
 */
public TextureRegion createTextureFromBytes(byte[] bytes) {
    Pixmap pixmap = new Pixmap(bytes, 0, bytes.length);
    final int orgWidth = pixmap.getWidth();
    final int orgHeight = pixmap.getHeight();
    int width = MathUtils.nextPowerOfTwo(orgWidth);
    int height = MathUtils.nextPowerOfTwo(orgHeight);
    final Pixmap potPixmap = new Pixmap(width, height, pixmap.getFormat());
    potPixmap.drawPixmap(pixmap, 0, 0, 0, 0, pixmap.getWidth(), pixmap.getHeight());
    pixmap.dispose();
    TextureRegion region = new TextureRegion(new Texture(potPixmap), 0, 0, orgWidth, orgHeight);
    potPixmap.dispose();
    return region;
}
 
Example 4
Source File: NinePatchEditorModel.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
/** @return original image pixmap with 1-pixel border 9-patch markup. */
public Pixmap prepareNinePatchPixmap() {
    Pixmap patchPixmap = new Pixmap(this.pixmap.getWidth() + 2, this.pixmap.getHeight() + 2, this.pixmap.getFormat());
    patchPixmap.setBlending(Pixmap.Blending.None);
    patchPixmap.drawPixmap(pixmap, 1, 1);

    patchPixmap.setColor(0x000000ff);
    if (patchValues.left.get() != 0 && patchValues.right.get() != 0) {
        for (int x = patchValues.left.get(); x < (pixmap.getWidth() - patchValues.right.get()); x++) {
            patchPixmap.drawPixel(x+1, 0);
        }
    }
    if (patchValues.top.get() != 0 && patchValues.bottom.get() != 0) {
        for (int y = patchValues.top.get(); y < (pixmap.getHeight() - patchValues.bottom.get()); y++) {
            patchPixmap.drawPixel(0, y+1);
        }
    }
    if (contentValues.left.get() != 0 && contentValues.right.get() != 0) {
        for (int x = contentValues.left.get(); x < (pixmap.getWidth() - contentValues.right.get()); x++) {
            patchPixmap.drawPixel(x+1, pixmap.getHeight()+1);
        }
    }
    if (contentValues.top.get() != 0 && contentValues.bottom.get() != 0) {
        for (int y = contentValues.top.get(); y < (pixmap.getHeight() - contentValues.bottom.get()); y++) {
            patchPixmap.drawPixel(pixmap.getWidth()+1, y+1);
        }
    }
    return patchPixmap;
}
 
Example 5
Source File: PixmapUtils.java    From libgdx-snippets with MIT License 5 votes vote down vote up
/**
 * Returns a copy of the given pixmap, cropped about the given dimensions.
 */
public static Pixmap crop(Pixmap pixmap, int left, int bottom, int width, int height) {

	Pixmap result = new Pixmap(width, height, pixmap.getFormat());
	result.drawPixmap(pixmap, 0, 0, left, bottom, width, height);

	return result;
}
 
Example 6
Source File: TextureUtil.java    From seventh with GNU General Public License v2.0 4 votes vote down vote up
public static Pixmap subPixmap(Pixmap pix, int x, int y, int width, int height) {
    Pixmap sub = new Pixmap(width, height, pix.getFormat());
    sub.drawPixmap(pix, x, y, width, height, 0, 0, width, height);
    return sub;
}
 
Example 7
Source File: TextureUtil.java    From seventh with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Resizes the image
 *
 * @param image
 * @param width
 * @param height
 * @return
 */
public static Pixmap resizePixmap(Pixmap image, int width, int height) {
    Pixmap pix = new Pixmap(width, height, image.getFormat());
    pix.drawPixmap(image, 0, 0, width, height, // destination
             0, 0, image.getWidth(), image.getHeight()); // source                         
    return pix;
}
 
Example 8
Source File: NinePatchEditorDialog.java    From gdx-skineditor with Apache License 2.0 2 votes vote down vote up
public void refreshPreview() {

		Gdx.app.log("NinePatchEditorDialog","refresh preview.");

		Pixmap pixmapImage = new Pixmap(Gdx.files.internal(textSourceImage.getText()));
		
		Pixmap pixmap = new Pixmap((int) (pixmapImage.getWidth()+2), (int) (pixmapImage.getHeight()+2), Pixmap.Format.RGBA8888);
		pixmap.drawPixmap(pixmapImage,1,1);

		pixmap.setColor(Color.BLACK);
		
		// Range left
		int h = pixmapImage.getHeight()+1;
		pixmap.drawLine(0, (int) (h * rangeLeft.rangeStart),0, (int) (h * rangeLeft.rangeStop));
		

		// Range top
		int w = pixmapImage.getWidth()+1;
		pixmap.drawLine((int) (w * rangeTop.rangeStart), 0,(int) (w * rangeTop.rangeStop), 0);

		// Range right
		h = pixmapImage.getHeight()+1;
		pixmap.drawLine(pixmapImage.getWidth()+1, (int) (h * rangeRight.rangeStart),pixmapImage.getWidth()+1, (int) (h * rangeRight.rangeStop));

		// Range bottom
		w = pixmapImage.getWidth()+1;
		pixmap.drawLine((int) (w * rangeBottom.rangeStart), pixmap.getHeight()-1,(int) (w * rangeBottom.rangeStop), pixmap.getHeight()-1);
		
		
		PixmapIO.writePNG(tmpFile, pixmap);
		
		pixmapImage.dispose();
		pixmap.dispose();

		FileHandle fh = new FileHandle(System.getProperty("java.io.tmpdir")).child("skin_ninepatch");
		TexturePacker.Settings settings = new TexturePacker.Settings();
		TexturePacker.process(settings, fh.path(), fh.path(), "pack");

		TextureAtlas ta = new TextureAtlas(fh.child("pack.atlas"));
		NinePatch np = ta.createPatch("button");
		NinePatchDrawable drawable = new NinePatchDrawable(np);
		reviewTablePreview();	
		buttonPreview1.getStyle().up = drawable;
		

	}