图片url转成Byte[],Byte[]转成Drawable
之所以要转成Byte[],是为了能方便的保存在本地
InputStream is = (InputStream) new URL(source).getContent();
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
int len=-1;
byte[] buffer=new byte[1024];
while ((len = is.read(buffer)) != -1) {
outStream.write(buffer, 0,len);
}
imgBuffer = outStream.toByteArray();
outStream.close();
is.close();
is=new ByteArrayInputStream(imgBuffer);
Drawable d = Drawable.createFromStream(is, "src");
is.close();
直接由url得到Drawable
InputStream is = (InputStream) new URL(source).getContent();
Drawable d = Drawable.createFromStream(is, "src");
is.close();