2015-01-09 41 views
0

我正在使用ACTION_IMAGE_CAPTURE來從攝像頭使用Intent捕獲圖像。 我使用此代碼:從動作圖像捕獲圖像錯誤意圖

Intent i = new Intent (MediaStore.ACTION_IMAGE_CAPTURE); 
      //startActivity(i); 
      startActivityForResult(i,1); 

並通過這個代碼獲取意圖的結果:

 InputStream stream = null; 
    if (requestCode == 1 && resultCode == Activity.RESULT_OK) 
     try 
     { 
      // recyle unused bitmaps 
      if (bitmap != null) { 
       bitmap.recycle(); 
      } 
      stream = getContentResolver().openInputStream(data.getData()); 
      bitmap = BitmapFactory.decodeStream(stream); 

      imgPic.setImageBitmap(bitmap); 
     } catch (FileNotFoundException e) 
     { 
      //e.printStackTrace(); 
      Log.e("ERROR 2 :->",e.toString()); 
     } 

      if (stream != null) 
      { 
       try 
       { 
        stream.close(); 
       } catch (IOException e) 
       { 
        //e.printStackTrace(); 
        Log.e("ERROR 3 :->",e.toString()); 
       } 
      } 

    } 

但是,當我在圖片預覽意圖然後點擊打勾按鈕,它給了我這個錯誤:

 1-10 00:55:34.675 25036-25036/com.digicare.digitrick W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x40e3d258) 
     01-10 00:55:34.686 25036-25036/com.digicare.digitrick E/AndroidRuntime﹕ FATAL EXCEPTION: main 
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { act=inline-data (has extras) }} to activity 

我在哪裏丟失了一些東西? 我如何在我的ImageView中獲取捕獲的圖像?

+0

你可以發佈你的整個onActivityResult? – 2015-01-09 20:23:34

+0

Andro Selva這是完整的代碼。只是缺少啓動線。 @Override protected void onActivityResult(int requestCode,int resultCode,Intent data){ – rehmak 2015-01-10 07:03:17

+0

然後可能會嘗試在第一行調用super.onactivityResult()。這可以幫助.. – 2015-01-12 16:49:44

回答

0

這可能是您的活動在Camera活動操作過程中被破壞,之後會重新創建,因爲Camera應用程序在資源方面很繁瑣。 您可以嘗試旋轉活動以強制您的活動銷燬並重新創建以檢查問題。

更多信息,請參閱〜這 why is UI/Activity destroyed after onActivityResult