当我尝试从 URL 字符串加载图像时,我收到MalformedURLException: Protocol not found 。当我粘贴该 URL 时,该图像显示在浏览器中。但不在 ImageView 中显示。我用过这段代码:
public static Bitmap getBitmapFromURL(String src) {
try
{
URL url = new URL(src);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
return myBitmap;
}
catch (IOException e) {
e.printStackTrace();
return null;
}
}
请有人告诉我有什么问题吗?这对我很有帮助。