Android - 如何从sqlite检索和显示图像? [英] Android - How to retrieve and display Image from sqlite?

查看:89
本文介绍了Android - 如何从sqlite检索和显示图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,对于我的Android应用程序,我可以成功地将图像作为字符串插入sqlite。但我不确定我是如何从数据库中检索此图像并将其转换为图像并在我的应用程序中显示它。坚持数周,帮助赞赏! :(



  //  按钮单击将图像保存到sqlite  

upload.setOnClickListener( new View.OnClickListener(){
< span class =code-sdkkeyword> @ Override
public void onClick (查看v){


学生= 学生(profadmin.getText()。toString());
student.setImageUri(ImageUri);
stud.updateImage(student);
Toast pass = Toast.makeText(ProfileActivity。 this ,< span class =code-string> 个人资料图片已更新,Toast.LENGTH_SHORT);
pass.show();

}
});

// 数据库处理程序:

public int updateImage(学生){
SQLiteDatabase db = getWritableDatabase();

ContentValues values = new ContentValues();

values.put(STUDENT_IMAGEURI,student.getImageUri()。toString());


int rowsAffected = db.update(STUDENT_TABLE,values,STUDENT_ADMINNO + =? new String [] { String .valueOf(student.getAdminNo())});
db.close();

return rowsAffected;
}





编辑:点击空的ImageView(profileIV)上传图片,打开android模拟器库,选择图片然后图像将显示在应用程序上。然后我点击上传按钮,然后将其发送到数据库并上传



  public   void  onActivityResult( int  reqCode, int  resCode,Intent data){

if (resCode == RESULT_OK){
if (reqCode == 1){
ImageUri = data.getData();
profileIV.setImageURI(data.getData());
}


}

解决方案

这些链接可以帮到你 -

视频 - 以sqllite存储图像 [ ^ ]

在Android应用程序的SQLite数据库中保存图像 [ ^ ]

在SQLlite中存储图像 [ ^

So for my android application i can successfully insert an image to sqlite as a string. But im not sure exactly how i can retrieve this image from the database and convert it to a Image and display it in my app. Stuck for weeks, help appreciated! :(

// Button Click saves image to sqlite

  upload.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {


            Student student = new Student(profadmin.getText().toString());
            student.setImageUri(ImageUri);
            stud.updateImage(student);
            Toast passes = Toast.makeText(ProfileActivity.this, "Profile Picture has been updated", Toast.LENGTH_SHORT);
            passes.show();

        }
    });

// Database Handler:

public int updateImage(Student student) {
    SQLiteDatabase db = getWritableDatabase();

    ContentValues values = new ContentValues();

    values.put(STUDENT_IMAGEURI, student.getImageUri().toString());


    int rowsAffected = db.update(STUDENT_TABLE, values, STUDENT_ADMINNO + "=?", new String[]{String.valueOf(student.getAdminNo())});
    db.close();

    return rowsAffected;
}



Edit: Uploaded the image by clicking the empty ImageView (profileIV) , opening the android emulator gallery, choose image and then image will be displayed on the app. Then i click the 'Upload' button and it sends it to the database and uploads

public void onActivityResult(int reqCode,int resCode,Intent data){

    if(resCode==RESULT_OK){
        if(reqCode==1){
            ImageUri = data.getData();
            profileIV.setImageURI(data.getData());
        }


    }

解决方案

These links should help you -
Video - store images in sqllite[^]
Saving An Image in a SQLite Database in Your Android Application[^]
Storing images in SQLlite[^]


这篇关于Android - 如何从sqlite检索和显示图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆