我正在开发一个应用程序,其中用户从图库中选择显示在recyclerview中的图像。我想将这些图像保存在sqlite数据库中,有什么办法吗?
我的代码是:
List<PhotoItem> picturesList = new ArrayList<>();
Uri uri = data.getData();
bitmap = decodeUri(uri,400);
PhotoItem photoItem = new PhotoItem();
photoItem.setPhoto(bitmap);
picturesList.add(photoItem);
答案 0 :(得分:1)
我建议将每个图像的路径作为VARCHAR
存储在数据库中。
答案 1 :(得分:0)
调用此函数并将您的位图转换为base64字符串:
from kivy.app import App
from kivy.lang import Builder
from textwrap import dedent
class MyApp(App):
def action(self,instance,value):
word_list = ["hello", "hi", "man", "girl"]
self.root.suggestion_text = ''
val = value[value.rfind(' ') + 1:]
if not val:
return
try:
word = [word for word in word_list
if word.startswith(val)][0][len(val):]
if not word:
return
self.root.suggestion_text = word
except IndexError:
print('Index Error.')
def build(self):
text_input = Builder.load_string(dedent('''
TextInput:
on_text: app.action(self, self.text)
'''))
return text_input
if __name__ == "__main__":
MyApp().run()
将此功能的结果保存在您的sqlite中
并从sqlite中读取您保存的字符串,并将其命名为
private String bitmapToBase64 (Bitmap bitmap) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
return Base64.encodeToString(baos.toByteArray(), Base64.DEFAULT);
}
修改您的代码:
private Bitmap base64ToBitmap (String base64) {
byte[] decodedString = Base64.decode(base64, Base64.DEFAULT);
return BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
}