Android自带图片裁剪

须知少年凌云志,曾许人间第一流。这篇文章主要讲述Android自带图片裁剪相关的知识,希望能为你提供帮助。
方法:

private void cutPhoto(Uri uri) { Intent intent = new Intent("com.android.camera.action.CROP"); intent.setDataAndType(uri, "image/*"); intent.putExtra("crop", true); // 裁剪框的比例,1:1 intent.putExtra("aspectX", 1); intent.putExtra("aspectY", 1); // 裁剪后输出图片的尺寸大小 intent.putExtra("outputX", 250); intent.putExtra("outputY", 250); intent.putExtra("outputFormat", "JPEG"); // 图片格式 intent.putExtra("noFaceDetection", true); // 取消人脸识别 intent.putExtra("return-data", true); startActivityForResult(intent, REQUEST_CUT_PHOTO); }

接收方法:
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) switch (requestCode) { case REQUEST_CUT_PHOTO: if (null != data) { Bitmap bitmap = data.getParcelableExtra("data"); upload(bitmap); } break; } }

 
大尺寸黑边问题:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null) .setType("image/*") .putExtra("crop", "true") .putExtra("aspectX", width) .putExtra("aspectY", height) .putExtra("outputX", width) .putExtra("outputY", height) .putExtra("scale", true)//黑边 .putExtra("scaleUpIfNeeded", true)//黑边 .putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f)) .putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());

【Android自带图片裁剪】 

    推荐阅读