2012-04-30 61 views

回答

0

使用此代碼:

fromGalleryButton.setOnClickListener(new View.OnClickListener() { 
         @Override 
         public void onClick(View v) { 
          //takePhotoFromGallery = true;// edited 

          Intent intent = new Intent(); 
          intent.setType("image/*"); 
          intent.setAction(Intent.ACTION_GET_CONTENT);// 

          startActivityForResult(Intent.createChooser(intent, "Select Picture"),10); 

         } 
        }); 

再補充一點:

@Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
     super.onActivityResult(requestCode, resultCode, data);  
     if (requestCode == 10 && resultCode == Activity.RESULT_OK) {    
      Uri contentUri = data.getData();   
      String[] proj = { MediaStore.Images.Media.DATA };   
      Cursor cursor = managedQuery(contentUri, proj, null, null, null);   
      int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);   
      cursor.moveToFirst();   
      imagePath = cursor.getString(column_index);   

      tempBitmap = BitmapFactory.decodeFile(imagePath); // this is your image 

     } 
} 
相關問題