很多網友平時如果需要在android平台下開發處理圖檔裁剪的應用,如果感覺實作的邏輯比較麻煩,比如說需要寫類此win32下的橡皮筋類crecttracker來設定裁剪區域,這裡android開發網給大家一個最簡單可靠的方法,通過下面的intent調用系統的camera程式的裁剪功能實作圖檔修剪。
intent intent = new intent("com.android.camera.action.crop");
intent.setclassname("com.android.camera", "com.android.camera.cropimage");
不過這裡android123提醒大家可能會出現無法找到activity的android.content.activitynotfoundexception異常,這是由于android内部的gallery和camera都有處理,可以嘗試另一種uri,com.android.gallery的com.android.camera.cropimage,在setclassname時,具體的代碼為
final intent intent = new intent("com.android.camera.action.crop");
intent.setclassname("com.android.camera", "com.android.camera.cropimage");
intent.setdata(uri.fromfile(mfile));
intent.putextra("outputx", width);
intent.putextra("outputy", height);
intent.putextra("aspectx", width);
intent.putextra("aspecty", height);
intent.putextra("scale", true);
intent.putextra("nofacedetection", true);
intent.putextra("output", uri.parse("file:/" + mfile.getabsolutepath()));
startactivityforresult(intent, request_crop_image);