Android內建圖片裁剪

來源:互聯網
上載者:User

標籤:

方法:

    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);// 取消Face Service        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內建圖片裁剪

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.