Skip to content

Instantly share code, notes, and snippets.

@phl0w
Created June 25, 2012 13:54
Show Gist options
  • Select an option

  • Save phl0w/2988771 to your computer and use it in GitHub Desktop.

Select an option

Save phl0w/2988771 to your computer and use it in GitHub Desktop.
Image img;
...
@Override
protected void setup() {
img = getImage("http://website.com/image.png", "image.png");
}
...
private Image getImage(String url, String name) {
try {
File dir = new File(System.getProperty("file.seperator") + name);
if (!dir.exists()) {
ImageIO.write(ImageIO.read(new URL(url)),
url.substring(url.lastIndexOf('.')).substring(1), dir);
}
return ImageIO.read(dir);
} catch (Exception a) {
a.printStackTrace();
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment