Statistics
| Revision:

root / trunk / applications / appCatalogAndGazetteerClient / src / es / gva / cit / catalog / protocols / GetImageFromWeb.java @ 15558

History | View | Annotate | Download (2.54 KB)

1

    
2
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
*
4
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
5
*
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
*
20
* For more information, contact:
21
*
22
*  Generalitat Valenciana
23
*   Conselleria d'Infraestructures i Transport
24
*   Av. Blasco Ib??ez, 50
25
*   46010 VALENCIA
26
*   SPAIN
27
*
28
*      +34 963862235
29
*   gvsig@gva.es
30
*      www.gvsig.gva.es
31
*
32
*    or
33
*
34
*   IVER T.I. S.A
35
*   Salamanca 50
36
*   46005 Valencia
37
*   Spain
38
*
39
*   +34 963163400
40
*   dac@iver.es
41
*/
42
package es.gva.cit.catalog.protocols;
43
import java.awt.image.BufferedImage;
44
import java.io.File;
45
import java.io.IOException;
46
import java.net.MalformedURLException;
47
import java.net.URL;
48

    
49
import javax.imageio.ImageIO;
50

    
51
/**
52
 * This class is used lo load an image from a URL. It saves the image
53
 * in a file
54
 * 
55
 * 
56
 * @author Jorge Piera Llodra (piera_jor@gva.es)
57
 */
58
public class GetImageFromWeb {
59

    
60
/**
61
 * It saves an image in a file
62
 * 
63
 * 
64
 * @return 
65
 * @param sUrl URL that contains the image
66
 * @param sfile File to save the image
67
 */
68
    public boolean getImageUrl(String sUrl, String sfile) {        
69
        URL url;
70
        try {
71
            url = new URL(sUrl);
72
            BufferedImage img = ImageIO.read(url);
73
            
74
            if (img == null)
75
                return false;            
76
            
77
            File outFile = new File(sfile);
78
                                   
79
            //We must to change this value: getCapabalilities request
80
            //has the supported formats
81
            return ImageIO.write(img, "jpeg", outFile);
82
        } catch (MalformedURLException e) {
83
            // TODO Auto-generated catch block
84
            System.out.println("La URL de la imagen no es correcta");
85
        } catch (IOException e1) {
86
            // TODO Auto-generated catch block
87
            System.out.println("No he podido leer la imagen desde la URL");
88
        }
89
        return false;
90
    } 
91
 }