List of usage examples for com.badlogic.gdx.graphics Pixmap getBlending
public static Blending getBlending()
From source file:com.kotcrab.vis.editor.module.physicseditor.util.Tracer.java
License:Apache License
public static Vector2[][] trace(String path, float hullTolerance, int alphaTolerance, boolean multiPartDetection, boolean holeDetection) { Blending blending = Pixmap.getBlending(); Pixmap.setBlending(Blending.None);//from www . ja va2s . c om Pixmap pixmap = new Pixmap(Gdx.files.absolute(path)); int w = pixmap.getWidth(); int h = pixmap.getHeight(); int size = w * h; int[] array = new int[size]; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int color = pixmap.getPixel(x, y); array[x + y * w] = color; } } pixmap.dispose(); Pixmap.setBlending(blending); Array<Array<Vector2>> outlines; try { outlines = TextureConverter.createPolygon(array, w, h, hullTolerance, alphaTolerance, multiPartDetection, holeDetection); } catch (Exception e) { return null; } TextureRegion region = new TextureRegion(new Texture(path)); float tw = region.getRegionWidth(); float th = region.getRegionHeight(); Vector2[][] polygons = new Vector2[outlines.size][]; for (int i = 0; i < outlines.size; i++) { Array<Vector2> outline = outlines.get(i); polygons[i] = new Vector2[outline.size]; for (int ii = 0; ii < outline.size; ii++) { polygons[i][ii] = outline.get(ii); polygons[i][ii].x /= tw; polygons[i][ii].y /= tw; polygons[i][ii].y = 1 * th / tw - polygons[i][ii].y; } } return polygons; }
From source file:com.o2d.pkayjava.editor.utils.poly.tracer.Tracer.java
License:Apache License
public static Vector2[][] trace(Texture texture, float hullTolerance, int alphaTolerance, boolean multiPartDetection, boolean holeDetection) { Blending blending = Pixmap.getBlending(); Pixmap.setBlending(Blending.None);//from ww w .ja va2s . c o m Pixmap pixmap = TextureUtils.getPOTPixmap(texture); int w = pixmap.getWidth(); int h = pixmap.getHeight(); int size = w * h; int[] array = new int[size]; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int color = pixmap.getPixel(x, y); array[x + y * w] = color; } } pixmap.dispose(); Pixmap.setBlending(blending); Array<Array<Vector2>> outlines; try { outlines = TextureConverter.createPolygon(array, w, h, hullTolerance, alphaTolerance, multiPartDetection, holeDetection); } catch (Exception e) { return null; } TextureRegion region = TextureUtils.getPOTTexture(texture); float tw = region.getRegionWidth(); float th = region.getRegionHeight(); Vector2[][] polygons = new Vector2[outlines.size][]; for (int i = 0; i < outlines.size; i++) { Array<Vector2> outline = outlines.get(i); polygons[i] = new Vector2[outline.size]; for (int ii = 0; ii < outline.size; ii++) { polygons[i][ii] = outline.get(ii); polygons[i][ii].x /= tw; polygons[i][ii].y /= tw; polygons[i][ii].y = 1 * th / tw - polygons[i][ii].y; } } return polygons; }
From source file:com.ridiculousRPG.GameBase.java
License:Apache License
/** * Takes a screenshot from the current frame buffer. The screenshot will be * stretched to fit into the Rectangle specified by dstW and dstH * // w w w . j a va 2 s . c o m * @param srcX * @param srcY * @param srcW * @param srcH * @param dstW * @param dstH * @return A Pixmap containing the screenshot. The screenshot will be * flipped at the y-axis. * @throws IOException */ public Pixmap takeScreenshot(int srcX, int srcY, int srcW, int srcH, int dstW, int dstH) throws IOException { Gdx.gl.glPixelStorei(GL10.GL_PACK_ALIGNMENT, 1); Pixmap pixmap = new Pixmap(srcW, srcH, Format.RGBA8888); Gdx.gl.glReadPixels(srcX, srcY, srcW, srcH, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, pixmap.getPixels()); // scale the picture if (srcW != dstW || srcH != dstH) { Pixmap scale = new Pixmap(dstW, dstH, Format.RGBA8888); Blending old = Pixmap.getBlending(); Pixmap.setBlending(Blending.None); scale.drawPixmap(pixmap, 0, 0, srcW, srcH, 0, 0, dstW, dstH); Pixmap.setBlending(old); pixmap.dispose(); pixmap = scale; } return pixmap; }