Revision 3566 trunk/applications/appCatalogYNomenclatorClient/src/es/gva/cit/catalogClient/protocols/GetImageFromWeb.java
GetImageFromWeb.java | ||
---|---|---|
1 |
|
|
1 | 2 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
2 | 3 |
* |
3 | 4 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
... | ... | |
39 | 40 |
* dac@iver.es |
40 | 41 |
*/ |
41 | 42 |
package es.gva.cit.catalogClient.protocols; |
42 |
|
|
43 | 43 |
import java.awt.image.BufferedImage; |
44 |
|
|
45 | 44 |
import java.io.File; |
46 | 45 |
import java.io.IOException; |
47 |
|
|
48 | 46 |
import java.net.MalformedURLException; |
49 | 47 |
import java.net.URL; |
50 |
|
|
51 | 48 |
import javax.imageio.ImageIO; |
52 | 49 |
|
53 |
|
|
54 |
|
|
55 | 50 |
/** |
56 | 51 |
* This class is used lo load an image from a URL. It saves the image |
57 | 52 |
* in a file |
53 |
* |
|
54 |
* |
|
58 | 55 |
* @author Jorge Piera Llodra (piera_jor@gva.es) |
59 | 56 |
*/ |
60 | 57 |
public class GetImageFromWeb { |
61 |
|
|
62 |
/** |
|
63 |
* It saves an image in a file |
|
64 |
* @param sUrl |
|
65 |
* URL that contains the image |
|
66 |
* @param sfile |
|
67 |
* File to save the image |
|
68 |
* @return |
|
69 |
*/ |
|
70 |
public boolean getImageUrl(String sUrl, String sfile) { |
|
71 |
URL url; |
|
72 | 58 |
|
59 |
/** |
|
60 |
* It saves an image in a file |
|
61 |
* |
|
62 |
* |
|
63 |
* @return |
|
64 |
* @param sUrl URL that contains the image |
|
65 |
* @param sfile File to save the image |
|
66 |
*/ |
|
67 |
public boolean getImageUrl(String sUrl, String sfile) { |
|
68 |
URL url; |
|
73 | 69 |
try { |
74 | 70 |
url = new URL(sUrl); |
75 |
|
|
76 | 71 |
BufferedImage img = ImageIO.read(url); |
77 | 72 |
|
78 | 73 |
if (img == null) |
... | ... | |
90 | 85 |
// TODO Auto-generated catch block |
91 | 86 |
System.out.println("No he podido leer la imagen desde la URL"); |
92 | 87 |
} |
93 |
|
|
94 | 88 |
return false; |
95 |
} |
|
96 |
} |
|
89 |
} |
|
90 |
} |
Also available in: Unified diff