简体   繁体   中英

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.

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? 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. 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. In my opinion this is the way to go (if you use SQLite anyway).

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM