码迷,mamicode.com
首页 > 移动开发 > 详细

Android自带图片裁剪

时间:2016-09-29 20:29:07      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:

方法:

    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自带图片裁剪

标签:

原文地址:http://www.cnblogs.com/guojing1991/p/5920726.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!