2015-01-01 55 views
0

hi iam目前正在開發一個android應用程序,用於將圖像存儲到數據庫,並將其檢索回圖像view.I將圖像轉換爲位放大器並將其上傳到mysql表 我的代碼是 以下代碼從ImageGallery獲取圖像:從sql表中查看圖像

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

然後插入$緩存表BLOB列類型 ,但我不知道如何來顯示從表中的形象圖的圖像位圖,請大家幫幫我在...

回答

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