标签:
方法:
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());
标签:
原文地址:http://www.cnblogs.com/guojing1991/p/5920726.html