繁体   English   中英

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

[英]How to Save Images In Database (SQLite) and load it to View : Android

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

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;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM