gpt4 book ai didi

android - 在线/离线图像管理策略

转载 作者:行者123 更新时间:2023-11-29 00:13:16 26 4
gpt4 key购买 nike

我正在开发一个应用程序,该应用程序将webservice 获取数据和图像并将其存储在设备中以供离线使用。同时,应用程序会将一些数据存储在 sqlite db 中,并将一些图像作为默认数据。

这是应用程序的流程:

  • 当应用程序打开时,它将从 Sqlite Db 中获取数据并存储在设备中的图像的图像路径并显示它们。
  • 此外,如果有互联网连接,数据和图像来自webservice 将被使用并复制到 Sqlite DB(data)以及稍后离线访问的device(images)

这里是问题:

What is the best strategy to do that (note that i want also to prevent images shown in gallery of the device. They will be able to be accesed only from the app)?

  • 我应该先将默认图像存储在 Assets 文件夹 中然后复制在第一次打开时将它们添加到外部目录。对于离线使用网络服务中的图片,下载并保存到同一个目录?
  • 我应该将本地镜像存储在可绘制对象中,而将下载的图像存储在设备的外部目录?
  • 我是否应该将所有图像存储在 SqliteDb 中作为二进制数据(我不更喜欢因为性能)

还要考虑到我想为不同的设备尺寸存储多个图像。因此,在第一次打开时,我检查设备从哪个 drawable 文件夹(xxhdpi、xhdpi、hdpi、mdpi) 中获取图像,如下所示:

 DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
switch(metrics.densityDpi){
case DisplayMetrics.DENSITY_MEDIUM:
break;
case DisplayMetrics.DENSITY_HIGH:
break;
case DisplayMetrics.DENSITY_XHIGH:
break;
case DisplayMetrics.DENSITY_XXHIGH:
break;
}

存储到它在 SharedPreferences 上的文件夹,所以当我从该服务下载图像时,它会到具有特定图像大小的特定文件夹 webservice 并捕获它们

What is the best and easy strategy to manage images in this case?

[注意:我不想使用 google 扩展文件,因为数据和图像会被频繁更新]

最佳答案

Should i store default images firstly in Assets Folder and copy them to the external directory on the first oppening. And for offline usage of the images from the webservice, download and save them to the same directory?

没有。当您启动应用程序并使用缓存机制时从服务器获取它们,因此当互联网不可用时它将从缓存文件夹中获取。对于这些,您可以使用 picasso 库,它可以很好地完成这些工作。

Should i store all images in SqliteDb as binary data (which i dont prefer because of performance)

不,您不应该将图像存储在 sqlite 数据库中,因为这会使您的应用程序数据库变得庞大。一般来说,如果我们想做这些类型的事情,那么我们只存储图像路径而不是二进制文件。

What is the best and easy strategy to manage images in this case?

当您调用服务获取位图时,检查设备密度,然后将高度和宽度发送到服务器,然后期望从服务器返回该大小,如 fetchImage?image_width=xxx&image_height=yyy

关于android - 在线/离线图像管理策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28656084/

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