2015-07-20 45 views
0

我想裁剪圖像,我可以實現這一點。如何使用裁剪選項直接打開圖像

我的代碼

Intent cropIntent = new Intent(Intent.ACTION_PICK, 
       android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);   
     cropIntent.setDataAndType(fileUri, "image/*"); 
     // set crop properties 
     cropIntent.putExtra("crop", "true");  
     cropIntent.putExtra("return-data", true);  
     startActivityForResult(cropIntent, CROP_PIC); 

其中fileUri包含的URI,我想從畫廊裁剪圖像的路徑。

使用此代碼警告打開選擇應用程序來選擇圖像,我想知道,雖然我已經通過圖像路徑,然後爲什麼它要求選擇應用程序打開圖像,當我選擇應用程序(通過畫廊),那麼我必須從圖庫中選擇圖像進行裁剪。

我想要一個解決方案,使用該解決方案,我的圖像只是用裁切選項打開,而不要求選擇要打開的應用程序?

可能嗎?請幫我實現它...

+0

有機會幾乎沒有,除非你使用的是內容,而不是觀衆的例子一些好的庫。結帳[這篇文章](http://stackoverflow.com/questions/5383797/open-an-image-using-uri-in-androids-default-gallery-image-viwer)。 – Matthias

+0

@androidcode你找到解決方案嗎? – Amy

回答

1

嘗試用此:

 String filename = "image.png"; 
    String path = "/mnt/sdcard/" + filename; 
    File f = new File(path); // 
    Uri imgUri= Uri.fromFile(f); 
    Intent intent = new Intent("com.android.camera.action.CROP"); 
      intent.setDataAndType(imgUri, "image/*"); 
      intent.putExtra("crop", "true"); 
      intent.putExtra("aspectX", 1); 
      intent.putExtra("aspectY", 1); 
      intent.putExtra("outputX", 50); 
      intent.putExtra("outputY", 50); 
      intent.putExtra("return-data", true); 
      startActivityForResult(intent, 1); 
+0

感謝你...它爲我工作 –

+0

快樂編碼:) – Amy