android - 如何减少获取位图所需的时间
问题描述
我在 Android 和 iOS 上有一个项目,有一个部分显示汽车的 360 度视图,在 iOS 中,我只从内部存储中获取 60 张图像,这些图像之前从互联网下载,这些图像在用户显示时显示开始向右或向左滑动汽车。这个过程只需要 200 毫秒就可以准备好与用户交互。
但在Android中我必须先将60张图像转换成位图,然后这个过程类似于iOS的过程。然而,这第一个过程,将它们全部转换为位图需要大约 3 秒或更多。我已经阅读了在许多信息源中在 Android 中显示图像的过程,并且似乎有必要为此任务使用位图,因此可以减少获取所有位图的时间吗?或者我可以保存位图以避免转换当用户再次打开相同的视图时,PNG 文件再次转换为新的位图?
我用来将 png 文件转换为位图对象的代码与 Android 开发人员文档推荐的代码相同:
https://developer.android.com/topic/performance/graphics/load-bitmap
我获取位图的源代码是:
public static Bitmap decodeSampledBitmapFromFile(String filePath, int reqWidth, int reqHeight) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(filePath, options);
options.inSampleSize = 1;
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
Bitmap bitmap =BitmapFactory.decodeFile(filePath, options);
Log.d("img360","bitmap res "+bitmap.getWidth()+ " h "+bitmap.getHeight());
return bitmap;
}
我真的很感谢你的帮助和支持。
解决方案
如果你想从互联网上下载图片并在android上显示只需放一个imageview并使用picaso或glide库它更快更容易
推荐阅读
- asp.net-core - 调用发布到服务器的页面后,ASP.Net Core Web Api 不起作用
- android - 我的 android 应用程序在版本 8 (Oreo) 中工作,但在版本 4.4 (KitKat) 中不工作
- asp.net-identity - 可以使用 AccessToken 或 Identity 令牌作为 Connect-AzureAD / MSGraph 的凭据吗?
- python - pyspark中的case语句问题
- javascript - 从导入的组件中读取值
- sql - PL SQL 过程不引发异常 no_data_found
- sql - 我在哪里可以在查询中放置“str”或“inst”?
- python-3.x - AttributeError:“元组”对象没有属性“asjson”
- r - 创建返回行名和最大值的函数
- python-3.x - 给定 RGB,如何在颜色栏中获取值?