閱讀841 返回首頁    go 阿裏雲 go 技術社區[雲棲]


Android裁剪圖片最簡單方法

 很多網友平時如果需要在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); 
 

最後更新:2017-04-02 06:51:46

  上一篇:go magento -- 推薦插件 --Ajax更新購物車數量 --Ajax Shopping Cart Quantity Update
  下一篇:go Android Zip文件解壓縮代碼