您的位置:首页 > 其它

通过图片url生成Bitmap对象和Drawable对象

2014-02-11 16:05 405 查看
/**

* @param urlpath

* @return Bitmap

* 根据图片url获取图片对象

*/

public static Bitmap getBitMBitmap(String urlpath) {

Bitmap map = null;

try {

URL url = new URL(urlpath);

URLConnection conn = url.openConnection();

conn.connect();

InputStream in;

in = conn.getInputStream();

map = BitmapFactory.decodeStream(in);

// TODO Auto-generated catch block

} catch (IOException e) {

e.printStackTrace();

}

return map;

}

/**

* @param urlpath

* @return Bitmap

* 根据url获取布局背景的对象

*/

public static Drawable getDrawable(String urlpath){

Drawable d = null;

try {

URL url = new URL(urlpath);

URLConnection conn = url.openConnection();

conn.connect();

InputStream in;

in = conn.getInputStream();

d = Drawable.createFromStream(in, "background.jpg");

// TODO Auto-generated catch block

} catch (IOException e) {

e.printStackTrace();

}

return d;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐