首页 > 代码库 > 使用系统默认接口来剪切图片

使用系统默认接口来剪切图片

如果调用系统的图片接口:

      Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
//		intent.addCategory(Intent.CATEGORY_OPENABLE);
//		intent.setType("image/*");
            startActivityForResult(intent, REQUEST_CODE_SELECT_PHOTO);

  @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
 if (requestCode == REQUEST_CODE_SELECT_PHOTO) {
            try {
                //onPhotoSelected(data);
                final Uri originalUri = data.getData();
                if (originalUri == null) {
                    return;
                }
                startPhotoZoom(originalUri);
            } catch (Exception e) {
                if (LogSettings.MARKET) {
                    MktLog.e(TAG, "onPhotoSelected() : " + e.getMessage());
                }
            }
            return;
        }
}

public void startPhotoZoom(Uri uri) {              //这个是调用裁剪图片的接口
        Intent intent = new Intent("com.android.camera.action.CROP");
        intent.setDataAndType(uri, "image/*");
        intent.putExtra("crop", "true");
        intent.putExtra("aspectX", 1);
        intent.putExtra("aspectY", 1);
        intent.putExtra("outputX", 150);
        intent.putExtra("outputY", 150);
        intent.putExtra("return-data", true);
        startActivityForResult(intent, REQUEST_CODE_SELECT_CUT_PHOTO);
    }

裁剪完在onActivityResult中可以用:

if(requestCode == REQUEST_CODE_SELECT_CUT_PHOTO) {
            try {
                Bitmap bm = data.getParcelableExtra("data");

            } catch (Exception e) {
                if (LogSettings.MARKET) {
                    MktLog.e(TAG, "onPhotoSelected() : " + e.getMessage());
                }
            }

裁剪图片的接口:



使用系统默认接口来剪切图片