我正在从 URL 下载图像并将其显示在ImageView
. 我需要以完整的原始大小下载图像。我试过 Glide、Picasso 和 Universal Image Loader,但没有成功。是否有任何图书馆或方法可以实现这一目标?我什至试着自己AsyncTask
做,像这样:
public class ImageLoader extends AsyncTask<Void, Void, Bitmap> {
@Override
protected Bitmap doInBackground(Void... params) {
try {
URL url = new URL(bundle.getString("selectedImage"));
HttpURLConnection conn =
(HttpURLConnection)url.openConnection();
conn.setReadTimeout(6000);
conn.setConnectTimeout(6000);
conn.setRequestMethod("GET");
conn.setDoInput(true);
conn.connect();
int respose = conn.getResponseCode();
InputStream is = conn.getInputStream();
BufferedInputStream bufferedInputStream = new
BufferedInputStream(is);
bitmap = BitmapFactory.decodeStream(bufferedInputStream);
return bitmap;
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
但没有成功。有人有什么可以帮助我的吗?