2016-11-21 99 views
0

我有問題。 這是我的應用程序已有的代碼,它的工作原理是這樣的:拍照>作物>上傳。 我不想裁剪照片,我該怎麼做?只需刪除dispatchCropImageIntent方法?Android應用產品照片

protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    Log.d(this.getClass().getSimpleName(), "onActivityResult"); 
    if (resultCode == RESULT_OK) { 
     if (requestCode == REQUEST_IMAGE_CAPTURE) { 
      File imageFile = new File(mCurrentPhotoPath); 
      if (imageFile.exists()) { 
       dispatchCropImageIntent(Uri.fromFile(imageFile)); 
      } 
     } else if (requestCode == REQUEST_IMAGE_FROM_GALLERY_SELECT) { 
      dispatchCropImageIntent(data.getData()); 
     } else if (requestCode == REQUEST_PICTURE_CROP) { 
      String filePath = Environment.getExternalStorageDirectory() 
        + "/temporary_holder.jpg"; 
      setCurrentBitmap(BitmapFactory.decodeFile(filePath)); 
     } else if(requestCode == CAMERA_ACTIVITY_CODE){ 
      // Get path 
      String path = data.getStringExtra(CustomCamera.OUT_PATH); 

      // Read file 
      byte[] imgData = AppFS.readFileFromPath(path); 
      if (imgData != null) { 
       Bitmap bitmap = BitmapFactory.decodeByteArray(imgData , 0, imgData.length); 
       // TODO: Do something with the image, it should be okay 
       //((ImageView)findViewById(R.id.img)).setImageBitmap(bitmap); 
      } else { 
       Log.e("Main", "Data is null"); 
      } 
     } 
    } 
    else{ 
     onBackPressed(); 
    } 
} 

和:

private void dispatchCropImageIntent(Uri uri) { 
    Intent cropImageIntent = new Intent("com.android.camera.action.CROP"); 
    cropImageIntent.setDataAndType(uri, "image/*"); 
    cropImageIntent.putExtra("crop", "true"); 
    cropImageIntent.putExtra("noFaceDetection", true); 
    cropImageIntent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString()); 
    // retrieve data on return 
    cropImageIntent.putExtra("return-data", true); 
    File f = new File(Environment.getExternalStorageDirectory(), 
      "/temporary_holder.jpg"); 
    try { 
     f.createNewFile(); 
    } catch (IOException ex) { 
     Log.e("io", ex.getMessage()); 
    } 

    uri = Uri.fromFile(f); 
    cropImageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri); 
    startActivityForResult(cropImageIntent, REQUEST_PICTURE_CROP); 
} 
+0

只需刪除dispatchCropImageIntent()方法並獲取該圖像路徑以備將來使用 – Vadivel

回答

0

如果我理解正確的話,你想使你的應用程序的工作是這樣的:需要照片>上傳。因此,您需要將dispatchCropImageIntent()setCurrentBitmap()上傳方法