如何在Android Studio中手动使用SQLite存储和检索图像



我正在尝试在SQLite中保存图像.我创建了一个应用程序,可以拍照并将其与保存的图像进行比较 SQLite.So 如何在SQLite中存储图像?

我使用 BLOB 数据类型来存储图像

新帐户.java

public void insertUserData()
{

/**
* STUDENT DATABASER
*/
ContentValues contentValues1 =  new ContentValues();
contentValues1.put(LoginEntryStudent.STUDENT_COLUMN_ROLL_NO,"17121070");
contentValues1.put(LoginEntryStudent.STUDENT_COLUMN_FIRST_NAME,"Gautam");
contentValues1.put(LoginEntryStudent.STUDENT_COLUMN_LAST_NAME,"Helange");
contentValues1.put(LoginEntryStudent.STUDENT_COLUMN_PHONE_NUMBER,"7517424135");
contentValues1.put(LoginEntryStudent.STUDENT_COLUMN_EMAIL_ID,"gautamhelange025@gmail.com");
contentValues1.put(LoginEntryStudent.STUDENT_COLUMN_GENDER,LoginEntryStudent.STUDENT_GENDER_MALE);

//what value put there so image will be save from my mobile gallery
contentValues1.put(LoginEntryStudent.STUDENT_COLUMN_IMAGE,"what put here");
Uri newUriStudent = getContentResolver().insert(LoginEntryStudent.CONTENT_URI_STUDENT,contentValues1);
Intent i = new Intent(NewAccount.this,WelcomeApp.class);
startActivity(i);
}

将您的图像转换为 Base64 格式,然后保存到 sqlite。

查看此链接的第一个答案,了解如何将图像转换为base64

最新更新