简体   繁体   English

将图像存储在应用程序内存中的最佳方法是什么?

[英]What is the best way to store the image in the memory of app?

I'm using sqlite db in my app and now I would like to allow user customize the background image make them able to select one from their gallery. 我在我的应用程序中使用sqlite db,现在我想允许用户自定义背景图片,使他们能够从图库中选择一个。

Should I just store the path to image and simpy refer to it every time or should I some how transfer the image to some text and store it completely in my db? 我应该只存储图像的路径,而simpy每次都引用它,还是应该将图像传输到某些文本并将其完全存储在数据库中? The second option prevents in case of picture being deleted from gallery. 第二个选项可以防止图片从图库中删除。 But I would like to know the most appropriate way of doing that. 但我想知道最合适的方法。

SQLite has a cursor limit of 1Mb. SQLite的游标限制为1Mb。 So, you will probably not be able to store it completely in the DB, when you go to to request it will probably be truncated. 因此,您可能无法将其完全存储在数据库中,当您去请求它可能会被截断。 Store the path to the image in the database table, and access it that way. 将映像的路径存储在数据库表中,并以这种方式访问​​它。

You wouldn't store it as text. 您不会将其存储为文本。 Store it as blob to your database. 将其作为blob存储到数据库中。 In my opinion this is the way to go (if you use SQLite anyway). 我认为这是可行的方法(如果仍然使用SQLite)。

If you have large images then store the path to your storage and not the image to the database. 如果图像较大,则将路径存储到存储,而不是将图像存储到数据库。

我认为最好只保存背景的路径,而不会受到图像大小的限制

In my opinion, the best way to save the customized background image is copy it into the internal storage (private storage) of your application. 我认为,保存自定义背景图片的最佳方法是将其复制到应用程序的内部存储(私有存储)中。 If you store only the path of the file, then file cannot be available once the user deleted that. 如果仅存储文件的路径,则用户删除文件后该文件将不可用。 The official docs saying about the internal storage is: 关于内部存储的官方文档是:

  • It's always available. 随时可用。
  • Files saved here are accessible by only your app by default. 默认情况下,仅您的应用可以访问此处保存的文件。
  • When the user uninstalls your app, the system removes all your app's files from internal storage. 当用户卸载您的应用程序时,系统将从内部存储中删除您所有应用程序的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将图片从Android应用存储到Datastore / Google Cloud Storage的最佳方法是什么? - What is the best way to store image from Android app to Datastore/Google Cloud Storage? 存储应用程序数据并将其加载到应用程序中的最佳方式是什么? - What is the best way to store app data and load it in app? Android-将图像存储到SQLite的最佳方法是什么? - Android - What's the best way to store image to SQLite? 在Android应用程序中存储文件的最佳方法是什么? - What is the best way to store a file within an Android app? 在Firebase中存储信息应用程序数据的最佳方法是什么? - What is the best way to store data for an information app in Firebase? Android:在Android中为应用程序离线存储JSON数据的最佳方法是什么? - Android: what is the best way to store JSON data offline for the app in android? 在Android应用程序上存储“收藏夹”等数据的最佳方法是什么? - what is the best way to store data such as 'Favorites' on an Android-app? 在Android应用程序中存储api-urls的最佳方法是什么? - What is the best way to store api-urls in android app? Android,将图像存储到SQLite数据库并从db获取图像的最佳方法是什么? - Android ,What Is The Best way to store image to SQLite database , and retreive image from db? Firebase:存储多个图像 URL 的最佳方式 - Firebase : Best way to store multiple image URLs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM