拍照后裁剪

private void doTakePhotoAction() {
    
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);


    //Wysie_Soh: Create path for temp file
    mImageCaptureUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(),
                        "tmp_contact_" + String.valueOf(System.currentTimeMillis()) + ".jpg"));


    intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mImageCaptureUri);


    try {
        intent.putExtra("return-data", true);
        startActivityForResult(intent, PICK_FROM_CAMERA);
    } catch (ActivityNotFoundException e) {
        //Do nothing for now
    }
}


protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != RESULT_OK) {
        return;
    }


    switch (requestCode) {


    case CROP_FROM_CAMERA: {
        //Wysie_Soh: After a picture is taken, it will go to PICK_FROM_CAMERA, which will then come here
        //after the image is cropped.


        final Bundle extras = data.getExtras();


        if (extras != null) {
            Bitmap photo = extras.getParcelable("data");


            mPhoto = photo;
            mPhotoChanged = true;
            mPhotoImageView.setImageBitmap(photo);
            setPhotoPresent(true);
        }


        //Wysie_Soh: Delete the temporary file                        
        File f = new File(mImageCaptureUri.getPath());            
        if (f.exists()) {
            f.delete();
        }


        InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        mgr.showSoftInput(mPhotoImageView, InputMethodManager.SHOW_IMPLICIT);


        break;
    }


    case PICK_FROM_CAMERA: {
        //Wysie_Soh: After an image is taken and saved to the location of mImageCaptureUri, come here
        //and load the crop editor, with the necessary parameters (96x96, 1:1 ratio)


        Intent intent = new Intent("com.android.camera.action.CROP");
        intent.setClassName("com.android.camera", "com.android.camera.CropImage");


        intent.setData(mImageCaptureUri);
        intent.putExtra("outputX", 96);
        intent.putExtra("outputY", 96);
        intent.putExtra("aspectX", 1);
        intent.putExtra("aspectY", 1);
        intent.putExtra("scale", true);
        intent.putExtra("return-data", true);            
        startActivityForResult(intent, CROP_FROM_CAMERA);


        break;


    }
    }
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值