2012-04-21 74 views
0

我正在使用Intent處理基於Android相機的應用程序。拍攝照片後,我可以看到照片和兩個按鈕 - 「保存」和「取消」。我想要做的是不要等待用戶選擇這兩個按鈕中的一個,而是開始處理這張照片,然後根據處理結果做出更進一步的動作。Android如何處理照片

我一直在做這種方式迄今:

CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100; 

protected void startCameraActivity() 
{ 
    Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 

    // the method below is my method for setting proper path for my image file 
    fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); // create a file to save the image 

    intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name 

    startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE); 
} 

這個方法被調用時我啓動我的應用程序。所以我用相機開始我的應用程序。 然後我拍一張照片。我可以選擇「保存」或「取消」。當我選擇一個這種方法被調用時:

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) { 
     if (resultCode == RESULT_OK) { 
      // Image captured and saved to fileUri specified in the Intent 

      onPhotoTaken(); // processing... 

     } else if (resultCode == RESULT_CANCELED) { 
      // User cancelled the image capture 
     } else { 
      // Image capture failed, advise user 
     } 
    } 
} 

在收到適當的resultCode後,我從文件加載該圖像,然後開始處理它。

現在我的問題是:如果我可以在onActivityResult方法被調用之前獲取該圖像?點擊其中一個按鈕後會調用它。

(我想這樣做的類似的方式谷歌谷歌做它 - 用戶拍攝照片並正在處理該照片的時候了)

+0

嘗試使用broadcoast接收器。 – 2012-04-22 06:41:48

回答

0

你將需要實現自己的拍照活動,一些沿着this(其中包括頁面末尾的源代碼)行的東西。

與使用簡單的Intent相比,它需要一些時間來設置它,但在此之後,您可以直接訪問所有相機功能,包括相機圖像,甚至在可用於調用活動之前。