天天看点

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); 

继续阅读