查看来自 sql table 的图像

Viewing image from sql table

你好,我目前正在开发一个 android 应用程序,该应用程序将图像存储到数据库并检索它以获取图像 view.I 将图像转换为 bit amp 并将其上传到 mysql table 我的代码是 以下代码从 ImageGallery 获取图像:

Intent i = new Intent(Intent.ACTION_PICK,
           android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
     startActivityForResult(i, ACTIVITY_SELECT_IMAGE); 

它将启动 ImageGallery,现在您可以 select 图像,并且在 onActivityResult 中您可以将图像解码为位图,如链接中所述:此处:

protected void onActivityResult(int requestCode, int resultCode, Intent     imageReturnedIntent) { 
     super.onActivityResult(requestCode, resultCode, imageReturnedIntent); 

   switch(requestCode) { 
    case REQ_CODE_PICK_IMAGE:
       if(resultCode == RESULT_OK){  
        Uri selectedImage = imageReturnedIntent.getData();
        String[] filePathColumn = {MediaStore.Images.Media.DATA};

        Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null,   null, null);
        cursor.moveToFirst();

        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        String filePath = cursor.getString(columnIndex);
        cursor.close();


        Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath);
     }
    }
  }

上传位图的php代码
到服务器:

  $base= $_REQUEST['yourselectedimage'];
  $buffer = mysql_real_escape_string($base);

然后将 $buffer 插入 table blob 列类型 但我不知道如何将图像位图从 table 显示到图像视图,请帮助我...

在您的 OnActivityresult 方法中,添加此代码示例。

 ImageView imageView = (ImageView) findViewById(R.id.imgView);
 imageView.setImageBitmap(BitmapFactory.decodeFile(filePath));

方法看起来像...

if(resultCode == RESULT_OK){  
        Uri selectedImage = imageReturnedIntent.getData();
        String[] filePathColumn = {MediaStore.Images.Media.DATA};

        Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null,   null, null);
        cursor.moveToFirst();

        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        String filePath = cursor.getString(columnIndex);
        cursor.close();

 ImageView imageView = (ImageView) findViewById(R.id.imgView);
                imageView.setImageBitmap(BitmapFactory.decodeFile(filePath));
        Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath);
     }