2011-02-01 6 views
1

は私がギャラリーを開くことができていますし、= コンテンツとして、ギャラリーのパスを取得:ImageViewの に//メディア/外部/画像/メディア/ 2 なく復号化することができる、これは私のコードギャラリーから写真を選ぶことができませんか?

ます。public voidですonCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.main);

  b=(Button) findViewById(R.id.Button01); 
      b.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,IMAGE_PICK); 
       } 
      }); 
     } 

     //UPDATED 
     public void onActivityResult(int requestCode, int resultCode, Intent data) { 
      if (resultCode == RESULT_OK) { 
       if (requestCode == IMAGE_PICK) { 
        Uri selectedImageUri = data.getData(); 


        //OI FILE Manager 
        filemanagerstring = selectedImageUri.getPath(); 

        //MEDIA GALLERY 
        selectedImagePath = getPath(selectedImageUri); 




        if(selectedImagePath!=null) 
        { 
         path = selectedImageUri.toString(); 
         m1.setPath(path); 


          BitmapFactory.Options options = new BitmapFactory.Options(); 
          options.inSampleSize = 4; 

          Bitmap yourSelectedImage = BitmapFactory.decodeFile(path, options); 
          ImageButton img2=(ImageButton)findViewById(R.id.widget27); 
          img2.setImageBitmap(yourSelectedImage); 
          Toast.makeText(getBaseContext(), path, 1000).show(); 

          } 



        } 
      } 
     } 
     public String getPath(Uri uri) { 





     String [] proj={MediaStore.Images.Media.DATA}; 
     Cursor cursor = managedQuery(uri, 
       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(); 

     return cursor.getString(column_index); 

}}

事前

コードのこの作品は、あなたのonActivityResultに配置する必要があります
+0

をしようとする

//ショーメッセージあなたはplsはウルQUEをeleborateことができますか?あなたはあなたが得るエラーとWHTエラーが出るWHR? –

答えて

6

に感謝を助けてください。それはあなたに取り込まれた画像URIからファイルパスを復号するための方法を提供します:

  Uri selectedImageUri = data.getData(); 
      String[] projection = { MediaStore.Images.Media.DATA}; 
      Cursor cursor = managedQuery(selectedImageUri, projection, null, null, null); 
      int column_index_data = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 
      cursor.moveToFirst(); 
      selectedImagePath = cursor.getString(column_index_data); 
      Bitmap galleryImage = BitmapFactory.decodeFile(selectedImagePath); 
+0

そんなにうまくいけばよろしいですか – kanchan

+0

私はそれが役に立ちましたことをうれしく思います。乾杯。 – Zelimir

0

私たちは、キットカットの上に、他のすべての以前にシームレスに実行するために私たちの以前のonActivityResult()さんのギャラリーピッカーのコードを次のように変更/修正を行う必要がありますバージョンも同様です。

Uri selectedImgFileUri = data.getData();

(selectedImgFileUri == NULL){

// user has not selected any photo 

}

試み{

入力ストリーム入力= mActivity.getContentResolver()openInputStream(selectedImgFileUri)場合。

mSelectedPhotoBmp = BitmapFactory.decodeStream(入力);

}キャッチ(ThrowableのTR){再び

}

関連する問題