2013-10-11 37 views
1

我在該主題上發現了相當多的線索,但不幸的是沒有人爲此問題提供答案。我想剪裁未指定尺寸的圖像,最後保存到新圖像。具有未指定尺寸的Android作物圖像

我此刻做什麼(爲了更好地觀看我離開了try/catch語句等):

 Intent cropIntent = new Intent("com.android.camera.action.CROP"); 
     cropIntent.setDataAndType(picUri, "image/*"); 
     cropIntent.putExtra("crop", "true"); 
     cropIntent.putExtra("outputX", 360); 
     cropIntent.putExtra("outputY", 360); 
     cropIntent.putExtra("return-data", true); 
     startActivityForResult(cropIntent, PIC_CROP); 

如果用戶想要一個樣方360x360或者一個矩形1024×768等。我不知道有沒有可能不指定具有固定值的outputx/Y?

+0

https://github.com/biokys/cropimage

代碼你找到一種方式來獲得它與未指定的尺寸和長寬比的工作? – Bashorings

+0

非常不幸的 – Markus

回答

2

改用此庫來裁剪圖像。從GitHub源

// create explicit intent 
Intent intent = new Intent(this, CropImage.class); 

// tell CropImage activity to look for image to crop 
String filePath = ...; 
intent.putExtra(CropImage.IMAGE_PATH, filePath); 

// allow CropImage activity to rescale image 
intent.putExtra(CropImage.SCALE, true); 

// if the aspect ratio is fixed to ratio 3/2 
intent.putExtra(CropImage.ASPECT_X, 3); 
intent.putExtra(CropImage.ASPECT_Y, 2); 

// start activity CropImage with certain request code and listen 
// for result 
startActivityForResult(intent, REQUEST_CODE_CROP_IMAGE); 
+0

經過一點點的工作我得到它運行,謝謝! – Markus

+0

只是一個問題,有沒有可能不設定固定比例? 我想讓用戶決定應該有多大的圖像 – Markus

+0

嘗試評論您將寬高比值設置爲intent extra的行。看看它是否有效 – Shubhank