2011-06-15 61 views
0

我寫了一個簡單的代碼可以從任何圖像支持的應用程序導入圖像導入圖片從Picasa在摩托羅拉XOOM

Intent intent = new Intent(Intent.ACTION_GET_CONTENT, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
intent.setType("image/*"); 
startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_FILE); 

代碼導入從圖庫圖片時,但只要我導入圖像從工作正常picasa在我的摩托羅拉xoom。它返回null,強制關閉NullPointerException

有沒有人對此有任何意見?

+0

在哪裏得到'NllPointerException'? – oliholz 2011-06-15 13:23:35

+0

將activityresult上的圖片導入爲位圖並使用其屬性後,我得到NullPointerException ..... – Rohan 2011-06-16 05:06:20

+0

Uri selectedImageUri = data.getData(); String selectedImagePath = imageUtil.getPath(selectedImageUri,Main.this); BitmapDrawable d =(BitmapDrawable)BitmapDrawable.createFromPath(selectedImagePath); 現在,雖然訪問「d.getWidth」,我得到NullPointerException .. – Rohan 2011-06-16 05:10:17

回答

0

ACTIVITYRESULT_CHOOSEPICTURE是您在調用startActivity(intent,requestCode)時使用的整數;

public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    if(requestCode == ACTIVITYRESULT_CHOOSEPICTURE) { 
    BitmapFactory.Options options = new BitmapFactory.Options(); 
    final InputStream is = context.getContentResolver().openInputStream(intent.getData()); 
    final Bitmap bitmap = BitmapFactory.decodeStream(is, null, options); 
    is.close(); 
    } 
相關問題