Question

I have a servlet that generate charts, based on given parameters.

I need to be able to save those charts in the server as a regular image: myImage.png for example.

These charts are created with a code like this:

http://127.0.0.1:8080/servlet/graficadorPS?type=area&val1=32.0|32.0|38.0|92.0&cat1=y|y|y|y&eje1=D|I|S|C&titulo=HF&ancho=130&alto=260

so, the image "per se" doesn't exist anywhere.

Is there a way to do this??

Was it helpful?

Solution

Sample code

public static void main(String[] args) throws NumberFormatException, IOException, ParseException {
    URL url  = new URL("http://cdn.portableapps.com/GoogleChromePortable_128.png");
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();

    InputStream is = conn.getInputStream();


      BufferedImage image = ImageIO.read(is);
      OutputStream os = new FileOutputStream(new File("output.png"));
      ImageIO.write(image, "png", os);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top