【问题标题】:How reduce the time than takes get a bitmap如何减少获取位图所需的时间
【发布时间】:2019-01-13 18:38:16
【问题描述】:

我在 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 performance bitmap storage


【解决方案1】:

如果您想从 Internet 下载图像并在 android 上显示它们 只需放一个 imageview 并使用 picaso 或 glide 库 它更快更容易

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-01
    • 1970-01-01
    • 2020-01-08
    相关资源
    最近更新 更多