gpt4 book ai didi

java - 简单的 Android 图像下载异步

转载 作者:行者123 更新时间:2023-12-01 11:54:52 26 4
gpt4 key购买 nike

我尝试通过 JSON 数据获取图像 URL,结果成功。下面的一切都运行缓慢。但是,我正在尝试找出一种方法,让 URL 在 Android Volley 或其他快速方法中显示得更快。我正在尝试将这些图像从 URL(也调整大小)下载到 MapView 图钉图标中。如果任何人都可以找到更有效的示例,我会全力以赴。如果您需要我提供更多信息,请告诉我。我正在遵循本指南:Android load from URL to Bitmap

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);

最佳答案

使用毕加索库:

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

它易于使用并且有很多有用的功能!
例如:

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

关于java - 简单的 Android 图像下载异步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28523099/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com