Android裁剪图片最简单方法

时间:2022-07-11 19:28:56
很多网友平时如果需要在Android平台下开发处理图片裁剪的应用,如果感觉实现的逻辑比较麻烦,比如说需要写类此Win32下的橡皮筋类CRectTracker来设置裁剪区域,这里Android开发网给大家一个最简单可靠的方法,通过下面的Intent调用系统的Camera程序的裁剪功能实现图片修剪。Java代码:01.Intent intent = new Intent("com.android.camera.action.CROP"); 02.intent.setClassName("com.android.camera", "com.android.camera.CropImage"); 复制代码不过这里Androideoe提醒大家可能会出现无法找到Activity的android.content.ActivityNotFoundException异常,这是由于Android内部的gallery和camera都有处理,可以尝试另一种URI,com.android.gallery的com.android.camera.CropImage,在setClassName时,具体的代码为 Java代码:01.final Intent intent = new Intent("com.android.camera.action.CROP"); 02.intent.setClassName("com.android.camera", "com.android.camera.CropImage"); 03.intent.setData(Uri.fromFile(mFile)); 04.intent.putExtra("outputX", width); 05.intent.putExtra("outputY", height); 06.intent.putExtra("aspectX", width); 07.intent.putExtra("aspectY", height); 08.intent.putExtra("scale", true); 09.intent.putExtra("noFaceDetection", true); 10.intent.putExtra("output", Uri.parse("file:/" + mFile.getAbsolutePath())); 11.startActivityForResult(intent, REQUEST_CROP_IMAGE); 复制代码