如何使用SQLite从图库中选择图片并另存为背景ImageView

少年巴雷托

我是Android编程的新手。我想知道如何从图库中选择图像并将其作为ImageView背景。我编写了从图库中选择代码并使其成为ImageView背景的代码,但是每次我离开应用程序时,图像都会消失。我必须保存在数据库中,但是我对此并不了解

如果有人可以帮助我..谢谢

我的Java档案

    ImageView btn1, btn2;
    Uri photoPath;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        btn1 = (ImageView) findViewById(R.id.imageView1);


        btn1.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {


                Intent intent = new Intent();
                intent.setType("image/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);
                startActivityForResult(Intent.createChooser(intent, "Altere o botão"), 1);
            }
        });

}

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

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

我的XML档案

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    tools:context="com.example.camera.MainActivity" >

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_launcher" 
    />

</LinearLayout>
罗希特·夏尔马

您必须使用将图像转换为字节,然后使用sqlLite数据库连接性来存储和检索图像表单数据库。为此,请参考以下示例:在Android的SQLLite数据库中存储图像的示例

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章