从sql表中查看图像

时间:2015-01-01 18:58:50

标签: android mysql sql-server bitmap android-sqlite

hi iam目前正在开发一个将图像存储到数据库的Android应用程序,并将其检索回来进行图像查看。我将图像转换为位放大器并将其上传到mysql表 我的代码是 以下代码从ImageGallery获取图片:

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

它将启动ImageGallery,现在您可以选择一个图像,在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插入表blob列类型 但我不知道如何将图像位图从表格显示到图像视图,请帮助我...

1 个答案:

答案 0 :(得分:1)

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