URL url = new URL(path);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(5000);
int max = conn.getContentLength();
InputStream is = conn.getInputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len;
while ((len = is.read(buffer)) != -1) {
baos.write(buffer, 0, len);
}
byte[] result = baos.toByteArray();
return BitmapFactory.decodeByteArray(result, 0, result.length);
} catch (Exception e) {
e.printStackTrace();
return null;
}
将一个图片的url地址转换为一个bitmap图片
最新推荐文章于 2024-08-12 04:07:39 发布