How to store image in SQLite database

后端 未结 6 1707
一整个雨季
一整个雨季 2020-11-22 02:38

In my application I am uploading an image from gallery and I want to store this image in the SQLite database. How do I store a bitmap in the database? I am converting bitmap

6条回答
  •  感情败类
    2020-11-22 02:54

    I have two things i need to note. How to store image from gallery and how to store image from uri e.g (www.example.com/myimage.png)

    How to store image from gallery

    Images are retrieved from gallery inform of Uri data type. Inorder to store images to android SQLite database, you need to convert the image uri to bitmap then to binary characters that is, bytes[] sequence. Then set the table column data type as BLOB data type. After retrieving the images from DB, convert the byte[] data type to bitmap in order to set it to imageview.

    how to store image from uri.

    Note that you can store images in DB as uri string but only image uri from a website. Convert the uri to string and insert it to your database. Retrieve your image uri as string and convert to uri data type in order to set it to imageview.

    You can try this post for worked program and source code how to store images in Sqlite database and display in listview

提交回复
热议问题