From 95bdef889af8282cbad5d42cddf200a7fd7e2cb8 Mon Sep 17 00:00:00 2001 From: AlphaRex12 Date: Sun, 13 Apr 2014 15:39:47 -0400 Subject: [PATCH] Added load Image from URL Load a image from a URL! --- .../thecherno/cherno/engine/graphics/Texture.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Cherno/src/com/thecherno/cherno/engine/graphics/Texture.java b/Cherno/src/com/thecherno/cherno/engine/graphics/Texture.java index 10355cd..a245d34 100644 --- a/Cherno/src/com/thecherno/cherno/engine/graphics/Texture.java +++ b/Cherno/src/com/thecherno/cherno/engine/graphics/Texture.java @@ -34,6 +34,21 @@ public static Texture load(String path) { return new Texture(width, height, pixels); } + public static Texture load(URL url) { + int width = 0, height = 0; + int[] pixels = null; + try { + BufferedImage image = ImageIO.read(url); + width = image.getWidth(); + height = image.getHeight(); + pixels = new int[width * height]; + image.getRGB(0, 0, width, height, pixels, 0, width); + } catch (IOException e) { + e.printStackTrace(); + } + return new Texture(width, height, pixels); + } + public int getWidth() { return width; }