【发布时间】:2018-02-23 11:35:19
【问题描述】:
我知道有很多关于同一问题的问题,并且我尝试了许多解决方案,例如this,但我仍然得到空字符串。 这是我的代码
try {
URL url = new URL(myUrl);
InputStream in = url.openConnection().getInputStream();
BufferedInputStream bis = new BufferedInputStream(in,1024*8);
ByteArrayOutputStream out = new ByteArrayOutputStream();
int len=0;
byte[] buffer = new byte[1024];
while((len = bis.read(buffer)) != -1) {
out.write(buffer, 0, len);
}
out.close();
bis.close();
byte[] data = out.toByteArray();
Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
d = new BitmapDrawable(getResources(), bmp);
} catch (FileNotFoundException e) {
d = getResources().getDrawable(R.mipmap.background);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
myUrl 是 firebase 存储 url
【问题讨论】:
-
有什么理由不使用像毕加索这样的东西(square.github.io/picasso)?
-
piccaso 和 glide 用于在 imageView 中设置图像,但我只想从 url 绘制
-
您可以从毕加索获取位图并转换为drawable
-
怎么样? @BurhanuddinRashid 你能用一段代码解释一下吗
标签: android bitmap drawable firebase-storage