2015-02-09 91 views
0

我無法在裁剪後檢索圖像,這裏是我的代碼一切正確嗎?我只是希望從裁剪圖庫圖像,然後將其上傳到一個ImageView的裁剪後無法檢索圖像Android

Intent intent = new Intent(); 
// call android default gallery 
intent.setType("image/*"); 
intent.setAction(Intent.ACTION_GET_CONTENT); 
// ******** code for crop image 
intent.putExtra("crop", "true"); 
intent.putExtra("aspectX", 1); 
intent.putExtra("aspectY", 1); 
intent.putExtra("outputX", 400); 
intent.putExtra("outputY", 400); 
intent.putExtra("scale", true); 
intent.putExtra("scaleUpIfNeeded", true); 
intent.putExtra(MediaStore.EXTRA_OUTPUT, "image"); 
intent.putExtra("outputFormat", Bitmap.CompressFormat.PNG.toString()); 

try { 
    intent.putExtra("return-data", false); 
    startActivityForResult(Intent.createChooser(intent, "Complete action using"), PICK_FROM_GALLERY); 
} 

protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    if (resultCode == RESULT_OK) { 
     if (requestCode == PICK_FROM_GALLERY) { 
      Bundle extras2 = data.getExtras(); 
      if (extras2 != null) { 
       photo = extras2.getParcelable("image"); 
       attachimage.setImageBitmap(photo); 
      } 
     } 

     if (requestCode == PICK_FROM_CAMERA) { 
      Bundle extras = data.getExtras(); 
      if (extras != null) { 
       photo = extras.getParcelable("data"); 
       attachimage.setImageBitmap(photo); 
      } 
     } 
    } 
} 
+0

什麼是應對?複製? – 2015-02-09 14:49:30

+0

@JaredBurrows他的意思是裁剪 – 2015-02-09 14:53:00

+0

裁剪,對錯誤感到抱歉 – 2015-02-09 14:55:35

回答

0
intent.putExtra("return-data", false); 

你不從這個您的活動導致收到的數據。

編輯(儘管有評論): 然後你做錯了,爲什麼在你請求其他輸出時從bundle中讀取數據呢? 看看這個問題&回答:Crop an Image by passing the image file path in Android

+0

我想從這個intent.putExtra檢索數據(MediaStore.EXTRA_OUTPUT,「image」); – 2015-02-09 15:10:03