显示从保存图片的路径数据库映像 [英] show image from database where you saved the path of image

查看:120
本文介绍了显示从保存图片的路径数据库映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有救我DATABSE图像的路径我。怎么能显示在屏幕上的形象呢?映像路径保存在列照片表contactTest1!
现在我可以在我的屏幕上显示的图像仅路径,这样每个联系人:

我用这个在dbconsole.java:

 私有静态的String [] FROM = {DbConstants.NAME,DbConstants.PHOTO,DbConstants.EMAIL,DbConstants.URL_STRING,DbConstants.ADRESS,DbConstants.PHONE,_ID};
     私有静态诠释[] TO = {R.id.name,R.id.edittext1};     私人无效showContacts(光标光标){
       //设置数据绑定
       SimpleCursorAdapter适配器=新SimpleCursorAdapter(这一点,R.layout.item,光标,FROM,TO);
       setListAdapter(适配器);

这在code我用它来获得图像的路径:

 按钮sButton =(按钮)findViewById(R.id.button1);
     sButton.setOnClickListener(新OnClickListener(){          公共无效的onClick(查看为arg0){
              //中的onCreate或任何事件在您希望用户
              //选择一个文件
              意向意图=新的Intent();
              intent.setType(图像/ *);
              intent.setAction(Intent.ACTION_GET_CONTENT);
              startActivityForResult(Intent.createChooser(意向,
                      选择图片),SELECT_PICTURE);
          }
      });
            公共无效的onActivityResult(INT申请code,INT结果code,意图数据){
       如果(结果code == RESULT_OK){
           如果(要求code == 1){
               // currImageURI是我使用容纳内容全局变量:// URI的图像
               乌里currImageURI = data.getData();
               getRealPathFromURI(currImageURI);           }
         }
       }
    公共字符串getRealPathFromURI(URI currImageURI){
       //可以张贴图片
       的String [] = PROJ {MediaStore.Images.Media.DATA};
       光标光标= managedQuery(currImageURI,
               PROJ,//哪些列返回
               空,// WHERE子句;该行返回(所有行)
               空,// WHERE子句选择参数(无)
               空值); //订单by子句(按名称升序)
       INT与Column_Index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
       cursor.moveToFirst();
          波萨=(EditText上)findViewById(R.id.editText1);
           poza.setText(currImageURI.toString());
          返回cursor.getString(Column_Index中);    }


解决方案

您将不得不延长SimpleCursorAdapter并覆盖getView(),这是在哪里,在你的列表中的每个项目,你可以在行中布局的数据。

有关的形象,我觉得有一个叫BitmapFactory类,你可以用它来从URL中创建图像,路径等等。我没有用它自己,所以不能举个例子,我害怕。

祝你好运!

Hello i have saved in my databse the path of an image .How can i show the image on the screen?The image path is saved in column "photo" in table "contactTest1" ! Now i can show on my screen only the path of image for each contact like this:

i use this in dbconsole.java:

     private static String[] FROM = { DbConstants.NAME, DbConstants.PHOTO, DbConstants.EMAIL,DbConstants.URL_STRING,DbConstants.ADRESS,DbConstants.PHONE,_ID};
     private static int[] TO ={R.id.name,R.id.edittext1};

     private void showContacts(Cursor cursor) {
       //set up data binding
       SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.item, cursor, FROM, TO);
       setListAdapter(adapter);

this the code i use to get path of image:

              Button sButton = (Button) findViewById(R.id.button1);
     sButton.setOnClickListener(new OnClickListener() {

          public void onClick(View arg0) {
              // in onCreate or any event where your want the user to
              // select a file
              Intent intent = new Intent();
              intent.setType("image/*");
              intent.setAction(Intent.ACTION_GET_CONTENT);
              startActivityForResult(Intent.createChooser(intent,
                      "Select Picture"), SELECT_PICTURE);
          }
      });




            public void onActivityResult(int requestCode, int resultCode, Intent data) {  
       if (resultCode == RESULT_OK) {
           if (requestCode == 1) {
               // currImageURI is the global variable I'm using to hold the content:// URI of the image
               Uri currImageURI = data.getData();
               getRealPathFromURI(currImageURI);

           }
         }
       }


    public String getRealPathFromURI(Uri currImageURI) {
       // can post image
       String [] proj={MediaStore.Images.Media.DATA};
       Cursor cursor = managedQuery( currImageURI,
               proj, // Which columns to return
               null,       // WHERE clause; which rows to return (all rows)
               null,       // WHERE clause selection arguments (none)
               null); // Order-by clause (ascending by name)
       int column_index =  cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
       cursor.moveToFirst();


          poza=(EditText)findViewById(R.id.editText1);
           poza.setText(currImageURI.toString());
          return cursor.getString(column_index);

    }

解决方案

You'll have to extend the SimpleCursorAdapter and override getView() which is where, for every item in your list, you can layout the data in the row.

For the image, I think there is a class called BitmapFactory which you can use to create images from urls, paths etc. I haven't used it myself, so can't give an example I'm afraid.

Good luck!

这篇关于显示从保存图片的路径数据库映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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