我一直試圖裁剪和調整圖像,同時通過相機意圖拍照,但不明白我在這裏做錯了 - 無法獲得裁剪圖像數據甚至如果該文件正確保存在手機上。Android相機意圖與作物
...
public class Add extends Activity {
private String imageFilePath;
...
protected void onCreate(Bundle savedInstanceState) {
...
imageFilePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/tmp/" + String.valueOf(System.currentTimeMillis()) + ".jpg";
imageFile = new File(imageFilePath);
imageFileUri = Uri.fromFile(imageFile);
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageFileUri);
intent.putExtra("crop", "true");
intent.putExtra("outputX", 600);
intent.putExtra("outputY", 600);
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("scale", true);
intent.putExtra("return-data", true);
startActivityForResult(intent, 0);
...
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch(requestCode) {
case 0 : {
Bitmap bitmap = BitmapFactory.decodeFile(imageFilePath);
}
}
}
如果我使用intent.putExtra("crop", "true");
,imageFilePath
返回NULL,如果沒有返回正確的文件。
感謝您的幫助!
感謝Dr.nik,所以你不能使用'intent.putExtra(「crop」,「true」);'用ACTION_IMAGE_CAPTURE意圖嗎?你需要首先捕獲一個意圖然後使用另一個意圖裁剪? – 2012-01-04 05:17:26
什麼是cropadaptor? – 2012-07-03 18:21:09
@BriceLechatellier它不穩定,在某些android設備上,相機應用程序崩潰。 FYI:http://stackoverflow.com/questions/13561026/taking-an-image-and-cropping-it – 2013-06-03 18:10:13