2012-07-05 26 views
2

我有我的主要項目,從某些來源獲取圖像(返回Uri)。下一步是裁剪圖像(觸摸輸入)。我最近發現,一些手機制造商陷入了Android基類,所以:如何獲取圖像路徑Uri和作物的所有設備

com.android.camera.action.crop 

並不總是存在。

所以我找到了一個裁剪庫:https://github.com/lvillani/android-cropimage 我已經將庫添加到我的eclipse構建路徑和項目庫中。

我的問題是,我可以打開庫,像這樣:

Intent intent = new Intent("com.android.camera.action.CROP"); 
    //intent.setClassName("com.android.camera", "com.android.camera.CropImage"); 
    intent.setDataAndType(uri, "image/*"); 
    intent.putExtra("crop", "true"); 
    intent.putExtra("output", Uri); 
    intent.putExtra("outputFormat", "JPEG"); 
    startActivityForResult(intent, 1); 

,然後檢索裁剪後的圖像或做我必須做別的多餘的?

  1. 另一個問題:還將這種影響我的應用程序,當我把它放到市場(將用戶需要下載或接受許可額外的庫

我想確保我的應用程序? (或者有更好的方法,請解釋一下(也保持簡單,相當新的Android開發!謝謝!)

+0

「我最近發現一些手機制造商亂搞了android基類,因此:com.android.camera.action.crop並不總是存在」 - 這不是「Android基類」。沒有人應該期待它或「com.android」中的其他任何東西,「永遠存在」。 – CommonsWare 2012-07-05 11:36:43

+0

好吧,這是包含這些庫的好習慣嗎?我做對了嗎?我以前從未在我的項目中使用過另一個庫,總是從頭開始創建所有的東西,但現在我需要時間,我沒有時間從頭開始創建裁剪級的類。你能給我一些建議嗎? – 2012-07-05 13:07:11

+1

「因此,包含這些庫的好習慣?」 - 開源的Android庫項目可能很有用。我自己發佈了一些它們。我從來沒有使用這個特定的庫,所以我不能評論你如何整合它。不幸的是,圖書館的作者沒有包括一個示例應用程序來演示如何使用它。 – CommonsWare 2012-07-05 13:15:18

回答

4

我安裝了庫並確保它連接到我的項目,並在建設路徑,然後我只是這樣做:

打開文件管理器:

 Intent intent = new Intent(); 
     intent.setType("image/*"); 
     intent.setAction(Intent.ACTION_GET_CONTENT); 
     startActivityForResult(Intent.createChooser(intent,"Select Picture"), PICK_FROM_FILE); 

或者,如果你想從攝像頭捕捉

 Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
     intent.putExtra("return-data", true); 
     startActivityForResult(intent, GET_IMAGE_FROM_CAMERA); 

然後裁剪圖像:

Intent intent = new Intent(this, com.android.camera.CropImage.class); 
    intent.setData(uri); 
    intent.putExtra("return-data", true); 
    startActivityForResult(intent, CROP); 

我已經上了幾個設備測試,這和它的工作得很好,花花公子。也適用於相機。

+0

奧利迪克森我從相機捕捉圖像和你的解決方案不適用於我..我正在使用neo v .. – 2012-12-19 07:37:20