Image from an URL [message #460066] |
Sun, 21 August 2005 17:47  |
Eclipse User |
|
|
|
Hello All.
Does anybody knows how can i download an image from internet with
SWT(Image)?????
I´m doing a program that connects with a movie's page, and i want to
download the cover for the movie that user selects...
I´m searching in Google, but i don´t find...
I´m creating Url objetc, inputstream, but i don´t know to do that!!
If someone gives me a url with a snippet, or post here, will be apreciated.
Thansk, and excuse for my bad english...
|
|
|
|
|
Re: Image from an URL [message #460221 is a reply to message #460179] |
Mon, 22 August 2005 18:40  |
Eclipse User |
|
|
|
Jeff Myers escribió:
> Here's a simplified snippet:
>
> try {
> URL url = new URL("http://www.google.com/intl/en/images/logo.gif");
> InputStream is = url.openStream();
> Image image = new Image(Display.getCurrent(), is);
> }
> catch (Exception e)
> {
> e.printStackTrace();
> }
> finally
> {
> is.close();
> }
>
> Hope this helps.
> - Jeff
Thanks... i will probe this little snippet..Yesterday i was probing a
snippet that i don´t know how, but functions...
------------------------------------------------------------ -----------
private void retrieveImage(String direccionImagen) {
ImageData[] imageDataArray,imageDataArray1;
URL url = null;
try {
url = new URL(direccionImagen);
} catch (MalformedURLException e) {
e.printStackTrace();
}
InputStream stream = null;
String urlfile=url.getFile();
NombreFichero nom=new NombreFichero(urlfile,'/');
// here i parse urlfile to obtain name and extension to save
// after...
try {
stream = url.openStream();
} catch (IOException e) {
e.printStackTrace();
}
ImageLoader loader = new ImageLoader();
imageDataArray = loader.load(stream);
String
pathCompleto=ProgramData.programImagesDir+System.getProperty ( "file.separator")+nom.nombreCompleto();
loader.save(pathCompleto,SWT.IMAGE_JPEG);
try {
stream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int imageDataIndex = 0;
Image image = new Image(GUI.display, imageDataArray[imageDataIndex]);
------------------------------------------------------------ -------------------------------
|
|
|
Powered by
FUDForum. Page generated in 0.07917 seconds