ImageLoader.java :  » Web » webcams-viewer » com » android » webcamsViewer » Android Open Source

Android Open Source » Web » webcams viewer 
webcams viewer » com » android » webcamsViewer » ImageLoader.java
package com.android.webcamsViewer;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;

/**
 * ImageLoader. Clase encargada de la lgica de negocio de descarga de imgenes
 * dese un servidor web.
 * 
 * @author irodriguez
 * 
 */
public class ImageLoader {
  /**
   * Realiza la descarga de una imagen especificada por su Url y devuelve un
   * objeto Bitmap represetando a la imagen
   * 
   * @param url
   *            Url de la imagen que debe ser descargada
   * @return Objeto bitmap que representa la imagen descargada
   */
  public Bitmap loader(String url) {
    Bitmap bm = null;
    try {
      URL aURL = new URL(url);
      URLConnection conn;
      conn = aURL.openConnection();
      conn.connect();
      InputStream is = conn.getInputStream();
      /* Buffered is always good for a performance plus. */
      BufferedInputStream bis = new BufferedInputStream(is);
      /* Decode url-data to a bitmap. */
      bm = BitmapFactory.decodeStream(bis);
      bis.close();
      is.close();
    } catch (IOException e) {
      Log.e("DEBUGTAG", "Remote Image Exception", e);

    }
    return bm;
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.