简单的Android镜像异步下载



我正试图通过JSON数据获取一个图像URL,它成功地工作了。下面的一切都进展缓慢。然而,我正试图找到一种方法,让URL在下面的Android Volley或其他快速方法中更快地显示。我正在尝试将这些图像从URL(也调整了大小)下载到MapView引脚图标中。如果有一个更有效的例子,任何人都可以找到,我很乐意。如果你需要更多的信息,请告诉我。我遵循这个指南:Android加载从URL到位图

final String profilePicture = profilePic;
URL url = new URL(profilePicture);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
Bitmap bit = BitmapFactory.decodeStream(is);
Bitmap b = Bitmap.createScaledBitmap(bit, 100, 100, false);
ByteArrayOutputStream out = new ByteArrayOutputStream();
b.compress(Bitmap.CompressFormat.JPEG, 10, out);
Bitmap decoded = BitmapFactory.decodeStream(new ByteArrayInputStream(out.toByteArray()));

bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(decoded);

使用picasso库:

http://square.github.io/picasso/

它很容易使用,并且有很多有用的功能
例如:

Picasso.with(context)
  .load(url)
  .resize(50, 50)
  .centerCrop()
  .into(imageView)

您可以使用Koushik离子库。它很容易使用。

[https://github.com/koush/ion][1]

最新更新