get Drawable From Url : Drawable « 2D Graphics « Android

Home
Android
1.2D Graphics
2.Animation
3.Core Class
4.Database
5.Date Type
6.Development
7.File
8.Game
9.Hardware
10.Media
11.Network
12.Security
13.UI
14.User Event
Android » 2D Graphics » Drawable 




get Drawable From Url
  
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;

class IOUtils {

  private static final String LOG_TAG = "IOUtils";
  public static final String PREFS_FILE = "javaeye.prefs";

  public static Drawable getDrawableFromUrl(URL url) {
    try {
      InputStream is = url.openStream();
      Drawable d = Drawable.createFromStream(is, "src");
      return d;
    catch (MalformedURLException e) {
      // e.printStackTrace();
    catch (IOException e) {
      // e.printStackTrace();
    }
    return null;
  }

  private static void copy(InputStream in, OutputStream out)
      throws IOException {
    byte[] b = new byte[1024];
    int read;
    while ((read = in.read(b)) != -1) {
      out.write(b, 0, read);
    }
  }

  private static void closeStream(Closeable stream) {
    if (stream != null) {
      try {
        stream.close();
      catch (IOException e) {
        // Log.e(LOG_TAG, e.getMessage());
      }
    }
  }

}

   
    
  














Related examples in the same category
1.Animate Drawables
2.ShapeDrawable Demo
3.Using GradientDrawable
4.Gets the image drawable from the url
5.Drawable.createFromStream
6.Drawable Manager
7.simply resizes a given drawable resource to the given width and height
8.Drawable.createFromStream and URL connection
9.Drawable Manager with Thread
10.get Drawable From Web Operation
11.Center a Drawable
12.Rotate around Center Point
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.