public Image load(InputStream in, boolean flipY) throws IOException{ ImageIO.setUseCache(false); BufferedImage img = ImageIO.read(in); if (img == null){ return null; } return load(img, flipY); }
Image jmeImage = new AWTLoader().load(image, true); return new Texture2D(jmeImage);
Image converted = loader.load(current, false); format = converted.getFormat(); output.add(converted.getData(0));
public Object load(AssetInfo info) throws IOException { if (ImageIO.getImageReadersBySuffix(info.getKey().getExtension()) != null){ boolean flip = ((TextureKey) info.getKey()).isFlipY(); InputStream in = null; try { in = info.openStream(); Image img = load(in, flip); if (img == null){ throw new AssetLoadException("The given image cannot be loaded " + info.getKey()); } return img; } finally { if (in != null){ in.close(); } } }else{ throw new AssetLoadException("The extension " + info.getKey().getExtension() + " is not supported"); } } }
public static void resizeToPowerOf2(Image image){ BufferedImage original = ImageToAwt.convert(image, false, true, 0); int potWidth = FastMath.nearestPowerOfTwo(image.getWidth()); int potHeight = FastMath.nearestPowerOfTwo(image.getHeight()); int potSize = Math.max(potWidth, potHeight); BufferedImage scaled = scaleDown(original, potSize, potSize); AWTLoader loader = new AWTLoader(); Image output = loader.load(scaled, false); image.setWidth(potSize); image.setHeight(potSize); image.setDepth(0); image.setData(output.getData(0)); image.setFormat(output.getFormat()); image.setMipMapSizes(null); }
public Image load(InputStream in, boolean flipY) throws IOException{ ImageIO.setUseCache(false); BufferedImage img = ImageIO.read(in); if (img == null) return null; return load(img, flipY); }
public Image load(InputStream in, boolean flipY) throws IOException{ ImageIO.setUseCache(false); BufferedImage img = ImageIO.read(in); if (img == null){ return null; } return load(img, flipY); }
public static Texture createTexture(BufferedImage bufferedImage) { Image image = awtLoader.load(bufferedImage, true); Texture texture = new Texture2D(image); return texture; }
/** this method calls dispose on Graphics2D g*/ public static Texture2D createTexture(BufferedImage img, Graphics2D g) { if (g != null) g.dispose(); AWTLoader loader = new AWTLoader(); Texture2D tex = new Texture2D(loader.load(img, true)); //changes to image parameter in buffer, affect the texture. tex.setMagFilter(Texture.MagFilter.Nearest); tex.setMinFilter(Texture.MinFilter.NearestNearestMipMap); return tex; } }
/** this method calls dispose on Graphics2D g*/ public static Texture2D createTexture(BufferedImage img, Graphics2D g) { if (g != null) g.dispose(); AWTLoader loader = new AWTLoader(); Texture2D tex = new Texture2D(loader.load(img, true)); //changes to image parameter in buffer, affect the texture. tex.setMagFilter(Texture.MagFilter.Nearest); tex.setMinFilter(Texture.MinFilter.NearestNearestMipMap); return tex; } }
public static void setImageOnTexture(Geometry geo, BufferedImage bufImg) { Texture texture = new Texture2D(bufImg.getWidth(), bufImg.getHeight(), Image.Format.Depth24); texture.setImage(new AWTLoader().load(bufImg, false)); geo.getMaterial().setTexture("ColorMap", texture); }
private void generateTexture() { if (material != null) { // The base image BufferedImage flower = new BufferedImage(64, 64, BufferedImage.TYPE_INT_ARGB); Graphics2D g = flower.createGraphics(); // Health ring drawImage(assetManager, g, flower.getWidth(), flower.getHeight(), "Textures/GUI/moods/H-0" + currentHealthIndex + ".png"); // The rest drawImage(assetManager, g, flower.getWidth(), flower.getHeight(), getCenterIcon()); drawImage(assetManager, g, flower.getWidth(), flower.getHeight(), getObjectiveIcon()); onTextureGenerated(g); // Dispose g.dispose(); // Convert the new image to a texture AWTLoader loader = new AWTLoader(); Texture tex = new Texture2D(loader.load(flower, false)); material.setTexture("ColorMap", tex); } }
@Override protected void controlUpdate(float fps) { cont += fps; if (cont > frecuency) { synchronized (buf) { if (imagCont > 0) { if (texture == null) { texture = new Texture2D(buf[index].getWidth(), buf[index].getHeight(), Image.Format.Depth24); texture.setImage(awtLoader.load(buf[index], true)); display.getMaterial().setTexture("ColorMap", texture); } else { texture.setImage(awtLoader.load(buf[index], true)); display.updateGeometricState(); } imagCont--; } } cont = 0f; } }
private Texture createTexture() throws IOException { String name = "ktorch"; //float[] scales = {1f, 1f, 1f, 1f}; //float[] offsets = new float[4]; //RescaleOp rop = new RescaleOp(scales, offsets, null); // Get the first frame, the frames need to be same size BufferedImage img = ImageIO.read(assetManager.locateAsset(new AssetKey(ConversionUtils.getCanonicalAssetKey("Textures/" + name + "0.png"))).openStream()); // Create image big enough to fit all the frames BufferedImage text = new BufferedImage(img.getWidth() * frames, img.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g = text.createGraphics(); g.drawImage(makeColorTransparent(img), 0, 0, null); for (int x = 1; x < frames; x++) { AssetInfo asset = assetManager.locateAsset(new AssetKey(ConversionUtils.getCanonicalAssetKey("Textures/" + name + x + ".png"))); img = ImageIO.read(asset.openStream()); g.drawImage(makeColorTransparent(img), img.getWidth() * x, 0, null); } g.dispose(); // Convert the new image to a texture AWTLoader loader = new AWTLoader(); Texture result = new Texture2D(loader.load(text, false)); return result; }
public Object load(AssetInfo info) throws IOException { if (ImageIO.getImageWritersBySuffix(info.getKey().getExtension()) != null){ boolean flip = ((TextureKey) info.getKey()).isFlipY(); InputStream in = null; try { in = info.openStream(); Image img = load(in, flip); return img; } finally { if (in != null){ in.close(); } } } return null; } }
public static Material createMaterialFromBufferedImage(JMEAssetLocator contentMan, BufferedImage bufferedImage) { Material material = new Material(contentMan.getAssetManager(), PHONG_ILLUMINATED_JME_MAT); Image image = awtLoader.load(bufferedImage, true); Texture texture = new Texture2D(image); material.setTexture("DiffuseMap", texture); if (bufferedImage.getColorModel().hasAlpha()) { material.getAdditionalRenderState().setBlendMode(BlendMode.Alpha); material.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off); } // material.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off); return material; }
public Object load(AssetInfo info) throws IOException { if (ImageIO.getImageReadersBySuffix(info.getKey().getExtension()) != null){ boolean flip = ((TextureKey) info.getKey()).isFlipY(); InputStream in = null; try { in = info.openStream(); Image img = load(in, flip); if (img == null){ throw new AssetLoadException("The given image cannot be loaded " + info.getKey()); } return img; } finally { if (in != null){ in.close(); } } }else{ throw new AssetLoadException("The extension " + info.getKey().getExtension() + " is not supported"); } } }
public static void resizeToPowerOf2(Image image){ BufferedImage original = ImageToAwt.convert(image, false, true, 0); int potWidth = FastMath.nearestPowerOfTwo(image.getWidth()); int potHeight = FastMath.nearestPowerOfTwo(image.getHeight()); int potSize = Math.max(potWidth, potHeight); BufferedImage scaled = scaleDown(original, potSize, potSize); AWTLoader loader = new AWTLoader(); Image output = loader.load(scaled, false); image.setWidth(potSize); image.setHeight(potSize); image.setDepth(0); image.setData(output.getData(0)); image.setFormat(output.getFormat()); image.setMipMapSizes(null); }
public static void resizeToPowerOf2(Image image){ BufferedImage original = ImageToAwt.convert(image, false, true, 0); int potWidth = FastMath.nearestPowerOfTwo(image.getWidth()); int potHeight = FastMath.nearestPowerOfTwo(image.getHeight()); int potSize = Math.max(potWidth, potHeight); BufferedImage scaled = scaleDown(original, potSize, potSize); AWTLoader loader = new AWTLoader(); Image output = loader.load(scaled, false); image.setWidth(potSize); image.setHeight(potSize); image.setDepth(0); image.setData(output.getData(0)); image.setFormat(output.getFormat()); image.setMipMapSizes(null); }
private Texture generateNormalMap(Texture texture) { BufferedImage image = ImageToAwt.convert(texture.getImage(), false, false, 0); BufferedImage normal = NormalMapFilter.create().filter(image, 0.01f); Image jme = new AWTLoader().load(normal, false); Texture2D jmeTexture = new Texture2D(jme); jmeTexture.setWrap(Texture.WrapAxis.S, texture.getWrap(Texture.WrapAxis.S)); jmeTexture.setWrap(Texture.WrapAxis.T, texture.getWrap(Texture.WrapAxis.T)); jmeTexture.setMagFilter(texture.getMagFilter()); jmeTexture.setMinFilter(texture.getMinFilter()); return jmeTexture; } }