如何在数据库(SQLite)中保存图像并将其加载到视图:Android

如何在数据库(SQLite)中保存图像并将其加载到视图:Android,android,eclipse,Android,Eclipse,如何在数据库中保存图像并重新加载到图像视图中查看? 不保存目录以显示图像,将文件(图像)移动到数据库 Android版本2.2尝试以下方法保存图像: private void saveDownloadedImage(Bitmap bmp, String id) { if (bmp != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bmp.compress(Bitmap

如何在数据库中保存图像并重新加载到图像视图中查看? 不保存目录以显示图像,将文件(图像)移动到数据库


Android版本2.2

尝试以下方法保存图像:

private void saveDownloadedImage(Bitmap bmp, String id) {
    if (bmp != null) {

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        bmp.compress(Bitmap.CompressFormat.PNG, 100, baos);
        byte[] imgBytes = baos.toByteArray();
        String base64String = Base64.encodeToString(imgBytes,
                Base64.DEFAULT);

        ContentValues initialValues = new ContentValues();

        initialValues.put("picture", base64String);

        // save your base64String to DB
    }
}
这是一组图像:

private Bitmap setImage(String base64String) {
    Bitmap bmp = null;
    try {
        if (base64String == null || base64String.equals("")) {


        } else {

            byte[] decodedString = Base64.decode(base64String, Base64.DEFAULT);
            bmp =  BitmapFactory.decodeByteArray(
                    decodedString, 0, decodedString.length);

        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return bmp;
}

与其将图像保存在数据库中,不如只存储其位置。请检查以下答案:@AdhikariBishwash我需要将图像导入并导出到数据库不需要base64。。。为了保存图像,我们可以使用BLOB<代码>初始值。输入(“图片”,单位为千兆字节)会有用的,toojay谢谢@Selvin你能解释更多吗?对于base64,图像会大1.37倍。。。您可以通过阅读sqlite文档或查看WhatsUp了解更多信息comment@Selvin请解释有关初始值的更多信息。输入(“图片”,单位:百万字节)百万字节??