Android: Saving Image to Database

前端 未结 2 904
有刺的猬
有刺的猬 2021-01-27 15:34

I have a activity with 3 ImageViews and a Button. Clicking on the ImageView shows an AlertDialog with a list of images (locat

相关标签:
2条回答
  • 2021-01-27 16:08

    I think the preferred solution is to store the images on the SD card and store the file paths in the database

    0 讨论(0)
  • 2021-01-27 16:21

    An SQLite database supports a NONE type affinity (you can use BLOB in CREATE TABLE statement) which allows you to store binary objects (like an image) inside the database as-is. This is the column type you should assign to the column to store your image in.

    Then, when you write your queries, you should parameterize your query, and bind your raw image data into something that can be inserted into the database using whatever API wrapper function supports BLOBs (I assume you have a special one for Android development), and do the same to read the data back. In the SQLite C API, you would use sqlite3_bind_blob(), and sqlite3_result_blob().

    0 讨论(0)
提交回复
热议问题