Android裁剪图片最简单方法

    xiaoxiao2021-12-14  17

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

    转载请注明原文地址: https://ju.6miu.com/read-964188.html

    最新回复(0)