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

来源:互联网 发布:wms钢铁加工软件 编辑:程序博客网 时间:2024/06/04 18:06
/**
* @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;
}
0 0
原创粉丝点击